Skip to content


Subversion checkout URL

You can clone with
Download ZIP


crash when exiting - previously launched embedded sub-shell #1045

dtlussier opened this Issue · 3 comments

3 participants


iPython consistently crashes when exiting (apple-D on OS X, or %exit) after launching an embedded sub-shell from within iPython.

To launch the embedded sub-shell I am using InteractiveShellEmbed() from IPython.frontend.terminal.embed as suggested on

Once I'm done with the embedded shell I quit it without difficulty via (%exit or apple-D), however when I go to exit the parent iPython shell iPython crashes.

I tried running the same operations using the regular Python interpreter and there are not problems. I am able to launch the interactive shell from regular Python and quit from both without difficulties.

The crash report is pasted below:


IPython post-mortem report

{'commit_hash': '<not found>',
 'commit_source': '(none found)',
 'ipython_path': '/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython',
 'ipython_version': '0.11',
 'os_name': 'posix',
 'platform': 'Darwin-10.8.0-i386-32bit',
 'sys_executable': '/Library/Frameworks/Python.framework/Versions/7.1/Resources/',
 'sys_platform': 'darwin',
 'sys_version': '2.7.2 |EPD 7.1-2 (32-bit)| (default, Jul 27 2011, 13:29:32) \n[GCC 4.0.1 (Apple Inc. build 5493)]'}



Crash traceback:

KeyErrorPython 2.7.2: /Library/Frameworks/Python.framework/Versions/7.1/Resources/
                                                   Fri Nov 25 12:28:04 2011
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
/Library/Frameworks/Python.framework/Versions/Current/bin/ipython in <module>()
      1 #!/Library/Frameworks/Python.framework/Versions/7.1/Resources/
      2 # This script was created by egginst when installing:
      3 #
      4 #   ipython-0.11-1.egg
      5 #
      6 if __name__ == '__main__':
      7     import sys
      8     from IPython.frontend.terminal.ipapp import launch_new_instance
---> 10     sys.exit(launch_new_instance())
        global sys.exit = <built-in function exit>
        global launch_new_instance = <function launch_new_instance at 0x12f9830>

/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython/frontend/terminal/ in launch_new_instance()
    368         ipython_dir = get_ipython_dir()
    369     profile_dir = os.path.join(ipython_dir, 'profile_default')
    370     cl = PyFileConfigLoader(default_config_file_name, profile_dir)
    371     try:
    372         config = cl.load_config()
    373     except IOError:
    374         # no config found
    375         config = Config()
    376     return config
    379 def launch_new_instance():
    380     """Create and run a full blown IPython instance"""
    381     app = TerminalIPythonApp.instance()
    382     app.initialize()
--> 383     app.start()
        app.start = <bound method TerminalIPythonApp.start of <IPython.frontend.terminal.ipapp.TerminalIPythonApp object at 0x2cae90>>
    386 if __name__ == '__main__':
    387     launch_new_instance()

/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython/frontend/terminal/ in start(self=<IPython.frontend.terminal.ipapp.TerminalIPythonApp object>)
    342         if gui or self.pylab:
    343             try:
    344       "Enabling GUI event loop integration, "
    345                               "toolkit=%s, pylab=%s" % (gui, self.pylab) )
    346                 activate(gui)
    347             except:
    348                 self.log.warn("Error in enabling GUI event loop integration:")
    351     def start(self):
    352         if self.subapp is not None:
    353             return self.subapp.start()
    354         # perform any prexec steps:
    355         if self.interact:
    356             self.log.debug("Starting IPython's mainloop...")
--> 357    = <bound method TerminalInteractiveShell.mainloop of <IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object at 0x1066a50>>
    358         else:
    359             self.log.debug("IPython not interactive...")
    362 def load_default_config(ipython_dir=None):
    363     """Load the default config file from the default ipython_dir.
    365     This is useful for embedded shells.
    366     """
    367     if ipython_dir is None:
    368         ipython_dir = get_ipython_dir()
    369     profile_dir = os.path.join(ipython_dir, 'profile_default')
    370     cl = PyFileConfigLoader(default_config_file_name, profile_dir)
    371     try:
    372         config = cl.load_config()

/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython/frontend/terminal/ in mainloop(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=None)
    207     #-------------------------------------------------------------------------
    208     # Mainloop and code execution logic
    209     #-------------------------------------------------------------------------
    211     def mainloop(self, display_banner=None):
    212         """Start the mainloop.
    214         If an optional banner argument is given, it will override the
    215         internally created default banner.
    216         """
    218         with nested(self.builtin_trap, self.display_trap):
    220             while 1:
    221                 try:
--> 222                     self.interact(display_banner=display_banner)
        self.interact = <bound method TerminalInteractiveShell.interact of <IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object at 0x1066a50>>
        display_banner = None
    223                     #self.interact_with_readline()                
    224                     # XXX for testing of a readline-decoupled repl loop, call
    225                     # interact_with_readline above
    226                     break
    227                 except KeyboardInterrupt:
    228                     # this should not be necessary, but KeyboardInterrupt
    229                     # handling seems rather unpredictable...
    230                     self.write("\nKeyboardInterrupt in interact()\n")
    232     def interact(self, display_banner=None):
    233         """Closely emulate the interactive Python console."""
    235         # batch run -> do not interact        
    236         if self.exit_now:
    237             return

/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython/frontend/terminal/ in interact(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=False)
    300             except:
    301                 # exceptions here are VERY RARE, but they can be triggered
    302                 # asynchronously by signal handlers, for example.
    303                 self.showtraceback()
    304             else:
    305                 self.input_splitter.push(line)
    306                 more = self.input_splitter.push_accepts_more()
    307                 if (self.SyntaxTB.last_syntax_error and
    308                     self.autoedit_syntax):
    309                     self.edit_syntax_error()
    310                 if not more:
    311                     source_raw = self.input_splitter.source_raw_reset()[1]
    312                     self.run_cell(source_raw)
    314         # We are off again...
--> 315         __builtin__.__dict__['__IPYTHON__active'] -= 1
        global __builtin__.__dict__ = {'bytearray': <type 'bytearray'>, 'IndexError': <type 'exceptions.IndexError'>, 'all': <built-in function all>, 'help': Type help() for interactive help, or help(object) for help about object., 'vars': <built-in function vars>, 'SyntaxError': <type 'exceptions.SyntaxError'>, 'unicode': <type 'unicode'>, 'UnicodeDecodeError': <type 'exceptions.UnicodeDecodeError'>, 'memoryview': <type 'memoryview'>, 'isinstance': <built-in function isinstance>, 'upgrade': Type upgrade() to open the Enthought page for upgrading to the full EPD., 'copyright': Copyright (c) 2001-2011 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'NameError': <type 'exceptions.NameError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'dict': <type 'dict'>, 'input': <built-in function input>, 'oct': <built-in function oct>, 'bin': <built-in function bin>, 'SystemExit': <type 'exceptions.SystemExit'>, 'StandardError': <type 'exceptions.StandardError'>, 'format': <built-in function format>, 'repr': <built-in function repr>, 'sorted': <built-in function sorted>, 'demo': Type demo() to select demos to run, or type e.g. demo('chaco'), 'False': False, 'RuntimeWarning': <type 'exceptions.RuntimeWarning'>, 'list': <type 'list'>, 'iter': <built-in function iter>, 'reload': <built-in function reload>, 'Warning': <type 'exceptions.Warning'>, '__package__': None, 'round': <built-in function round>, 'dir': <built-in function dir>, 'cmp': <built-in function cmp>, 'set': <type 'set'>, 'bytes': <type 'str'>, 'reduce': <built-in function reduce>, 'intern': <built-in function intern>, 'issubclass': <built-in function issubclass>, 'Ellipsis': Ellipsis, 'EOFError': <type 'exceptions.EOFError'>, 'locals': <built-in function locals>, 'BufferError': <type 'exceptions.BufferError'>, 'slice': <type 'slice'>, 'enthought': Enthought also offers Python training, taught by full-time Enthought
developers. Our open courses, custom courses, and webinars are geared
toward scientists, engineers and analysts who want to incorporate
Python into their workflow.  Our most popular courses include Python for
Scientists and Engineers, Python for Quants, and Python for Geophysicists.
We also have a number of targeted 1-day modules on advanced topics.

For more information, please visit:, 'FloatingPointError': <type 'exceptions.FloatingPointError'>, 'sum': <built-in function sum>, 'getattr': <built-in function getattr>, 'abs': <built-in function abs>, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'print': <built-in function print>, 'True': True, 'FutureWarning': <type 'exceptions.FutureWarning'>, 'ImportWarning': <type 'exceptions.ImportWarning'>, 'None': None, 'hash': <built-in function hash>, 'ReferenceError': <type 'exceptions.ReferenceError'>, 'len': <built-in function len>, 'credits':     Thanks to CWI, CNRI,, Zope Corporation and a cast of thousands
    for supporting Python development.  See for more information., 'frozenset': <type 'frozenset'>, '__name__': '__builtin__', 'ord': <built-in function ord>, 'packages': Packages are most easily managed using the enpkg command line tool.
Type packages() for information about installed and available packages., 'super': <type 'super'>, 'TypeError': <type 'exceptions.TypeError'>, 'license': Type license() to see the full license text, 'KeyboardInterrupt': <type 'exceptions.KeyboardInterrupt'>, 'UserWarning': <type 'exceptions.UserWarning'>, 'filter': <built-in function filter>, 'range': <built-in function range>, 'staticmethod': <type 'staticmethod'>, 'SystemError': <type 'exceptions.SystemError'>, 'BaseException': <type 'exceptions.BaseException'>, 'pow': <built-in function pow>, 'RuntimeError': <type 'exceptions.RuntimeError'>, 'float': <type 'float'>, 'MemoryError': <type 'exceptions.MemoryError'>, 'StopIteration': <type 'exceptions.StopIteration'>, 'globals': <built-in function globals>, 'divmod': <built-in function divmod>, 'enumerate': <type 'enumerate'>, 'apply': <built-in function apply>, 'LookupError': <type 'exceptions.LookupError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'basestring': <type 'basestring'>, 'UnicodeError': <type 'exceptions.UnicodeError'>, 'zip': <built-in function zip>, 'hex': <built-in function hex>, 'long': <type 'long'>, 'next': <built-in function next>, 'ImportError': <type 'exceptions.ImportError'>, 'chr': <built-in function chr>, 'xrange': <type 'xrange'>, 'type': <type 'type'>, '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'Exception': <type 'exceptions.Exception'>, 'tuple': <type 'tuple'>, 'UnicodeTranslateError': <type 'exceptions.UnicodeTranslateError'>, 'reversed': <type 'reversed'>, 'UnicodeEncodeError': <type 'exceptions.UnicodeEncodeError'>, 'IOError': <type 'exceptions.IOError'>, 'hasattr': <built-in function hasattr>, 'delattr': <built-in function delattr>, 'setattr': <built-in function setattr>, 'raw_input': <built-in function raw_input>, 'SyntaxWarning': <type 'exceptions.SyntaxWarning'>, 'compile': <built-in function compile>, 'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'str': <type 'str'>, 'property': <type 'property'>, 'GeneratorExit': <type 'exceptions.GeneratorExit'>, 'int': <type 'int'>, '__import__': <built-in function __import__>, 'KeyError': <type 'exceptions.KeyError'>, 'coerce': <built-in function coerce>, 'PendingDeprecationWarning': <type 'exceptions.PendingDeprecationWarning'>, 'file': <type 'file'>, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, 'unichr': <built-in function unichr>, 'id': <built-in function id>, 'OSError': <type 'exceptions.OSError'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'min': <built-in function min>, 'UnicodeWarning': <type 'exceptions.UnicodeWarning'>, 'execfile': <built-in function execfile>, 'any': <built-in function any>, 'complex': <type 'complex'>, 'bool': <type 'bool'>, 'ValueError': <type 'exceptions.ValueError'>, 'NotImplemented': NotImplemented, 'map': <built-in function map>, 'buffer': <type 'buffer'>, 'max': <built-in function max>, 'object': <type 'object'>, 'TabError': <type 'exceptions.TabError'>, 'callable': <built-in function callable>, 'ZeroDivisionError': <type 'exceptions.ZeroDivisionError'>, 'eval': <built-in function eval>, '__debug__': True, 'IndentationError': <type 'exceptions.IndentationError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'classmethod': <type 'classmethod'>, 'UnboundLocalError': <type 'exceptions.UnboundLocalError'>, 'NotImplementedError': <type 'exceptions.NotImplementedError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'OverflowError': <type 'exceptions.OverflowError'>}
    317         # Turn off the exit flag, so the mainloop can be restarted if desired
    318         self.exit_now = False
    320     def raw_input(self, prompt=''):
    321         """Write a prompt and read a line.
    323         The returned line does not include the trailing newline.
    324         When the user enters the EOF key sequence, EOFError is raised.
    326         Optional inputs:
    328           - prompt(''): a string to be printed to prompt the user.
    330           - continue_prompt(False): whether this line is the first one or a

KeyError: '__IPYTHON__active'


History of session input:interactive.launch_ipython()from mdhandle import interactiveinteractive.launch_ipython()
*** Last line of input (may not be in above history):

duplicate of #676

@minrk minrk closed this

To summarise that bug: for now, embedding IPython inside IPython will break things. We hope to fix that in the future, but it may take some time.


Ok - I think I can avoid embedding IPython in IPython by looking for get_ipython method. For my purposes this is fine, as I was really just looking to have IPython available when otherwise running code in the regular Python interpreter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.