From a63abfd90305d0cd6904f156b0ecf216f0b24467 2013-04-10 09:08:30 From: Thomas Spura Date: 2013-04-10 09:08:30 Subject: [PATCH] Report if cwd does not exist and raise exception in BaseIPythonApplication Catch the exception in the starting scripts, report the exception and exit gracefully. Do not directly exit in BaseIPythonApplication so that external applications can also catch the exception instead of exiting. --- diff --git a/IPython/core/application.py b/IPython/core/application.py index b13410d..11f1bd7 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -147,18 +147,12 @@ class BaseIPythonApplication(Application): def __init__(self, **kwargs): super(BaseIPythonApplication, self).__init__(**kwargs) # ensure current working directory exists - level_up = False - while True: - try: - directory = os.getcwdu() - except OSError: - # search level up until directory exists - os.chdir("..") - level_up = True - else: - if level_up: - self.log.warn("Current working directory doesn't exist.\nSetting to: %s"%(directory)) - break + try: + directory = os.getcwdu() + except: + # raise exception + self.log.error("Current working directory doesn't exist.") + raise # ensure even default IPYTHONDIR exists if not os.path.exists(self.ipython_dir): diff --git a/IPython/parallel/scripts/ipcluster b/IPython/parallel/scripts/ipcluster index 066a343..629d390 100755 --- a/IPython/parallel/scripts/ipcluster +++ b/IPython/parallel/scripts/ipcluster @@ -11,8 +11,15 @@ #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- - +import sys +import traceback from IPython.parallel.apps.ipclusterapp import launch_new_instance -launch_new_instance() +try: + launch_new_instance() +except: + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback, + file=sys.stderr) + sys.exit(1) diff --git a/IPython/parallel/scripts/ipcontroller b/IPython/parallel/scripts/ipcontroller index 1939d96..60bab10 100755 --- a/IPython/parallel/scripts/ipcontroller +++ b/IPython/parallel/scripts/ipcontroller @@ -11,8 +11,15 @@ #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- - +import sys +import traceback from IPython.parallel.apps.ipcontrollerapp import launch_new_instance -launch_new_instance() +try: + launch_new_instance() +except: + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback, + file=sys.stderr) + sys.exit(1) diff --git a/IPython/parallel/scripts/ipengine b/IPython/parallel/scripts/ipengine index 9c178a4..5658b24 100755 --- a/IPython/parallel/scripts/ipengine +++ b/IPython/parallel/scripts/ipengine @@ -11,10 +11,15 @@ #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- - +import sys +import traceback from IPython.parallel.apps.ipengineapp import launch_new_instance -launch_new_instance() - - +try: + launch_new_instance() +except: + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback, + file=sys.stderr) + sys.exit(1) diff --git a/IPython/parallel/scripts/iplogger b/IPython/parallel/scripts/iplogger index 1ae833a..c2af619 100755 --- a/IPython/parallel/scripts/iplogger +++ b/IPython/parallel/scripts/iplogger @@ -11,10 +11,15 @@ #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- - +import sys +import traceback from IPython.parallel.apps.iploggerapp import launch_new_instance -launch_new_instance() - - +try: + launch_new_instance() +except: + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback, + file=sys.stderr) + sys.exit(1) diff --git a/IPython/scripts/ipython b/IPython/scripts/ipython index b435148..ddb17f9 100755 --- a/IPython/scripts/ipython +++ b/IPython/scripts/ipython @@ -1,7 +1,15 @@ #!/usr/bin/env python """Terminal-based IPython entry point. """ +import sys +import traceback from IPython.frontend.terminal.ipapp import launch_new_instance -launch_new_instance() +try: + launch_new_instance() +except: + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback, + file=sys.stderr) + sys.exit(1)