ipython/ipython — Issue #1045: crash when exiting - previously launched embedded sub-shell
Author: dtlussier
Created: 2011-11-25 18:37:57+00:00
State: open

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 http://ipython.org/ipython-doc/dev/interactive/reference.html#embedding-ipython.

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': '',
'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/Python.app/Contents/MacOS/Python',
'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/Python.app/Contents/MacOS/Python
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 ()
1 #!/Library/Frameworks/Python.framework/Versions/7.1/Resources/Python.app/Contents/MacOS/Python
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
9
---> 10 sys.exit(launch_new_instance())
global sys.exit =
global launch_new_instance =

/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py 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
377
378
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 = >
384
385
386 if __name__ == '__main__':
387 launch_new_instance()

/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py in start(self=)
342 if gui or self.pylab:
343 try:
344 self.log.info("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:")
349 self.shell.showtraceback()
350
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 self.shell.mainloop()
self.shell.mainloop = >
358 else:
359 self.log.debug("IPython not interactive...")
360
361
362 def load_default_config(ipython_dir=None):
363 """Load the default config file from the default ipython_dir.
364
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/interactiveshell.py in mainloop(self=, display_banner=None)
207 #-------------------------------------------------------------------------
208 # Mainloop and code execution logic
209 #-------------------------------------------------------------------------
210
211 def mainloop(self, display_banner=None):
212 """Start the mainloop.
213
214 If an optional banner argument is given, it will override the
215 internally created default banner.
216 """
217
218 with nested(self.builtin_trap, self.display_trap):
219
220 while 1:
221 try:
--> 222 self.interact(display_banner=display_banner)
self.interact = >
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")
231
232 def interact(self, display_banner=None):
233 """Closely emulate the interactive Python console."""
234
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/interactiveshell.py in interact(self=, 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)
313
314 # We are off again...
--> 315 __builtin__.__dict__['__IPYTHON__active'] -= 1
global __builtin__.__dict__ = {'bytearray': , 'IndexError': , 'all': , 'help': Type help() for interactive help, or help(object) for help about object., 'vars': , 'SyntaxError': , 'unicode': , 'UnicodeDecodeError': , 'memoryview': , '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 BeOpen.com.
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': , 'BytesWarning': , 'dict': , 'input': , 'oct': , 'bin': , 'SystemExit': , 'StandardError': , 'format': , 'repr': , 'sorted': , 'demo': Type demo() to select demos to run, or type e.g. demo('chaco'), 'False': False, 'RuntimeWarning': , 'list': , 'iter': , 'reload': , 'Warning': , '__package__': None, 'round': , 'dir': , 'cmp': , 'set': , 'bytes': , 'reduce': , 'intern': , 'issubclass': , 'Ellipsis': Ellipsis, 'EOFError': , 'locals': , 'BufferError': , '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: www.enthought.com, 'FloatingPointError': , 'sum': , 'getattr': , 'abs': , 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'print': , 'True': True, 'FutureWarning': , 'ImportWarning': , 'None': None, 'hash': , 'ReferenceError': , 'len': , 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information., 'frozenset': , '__name__': '__builtin__', 'ord': , 'packages': Packages are most easily managed using the enpkg command line tool.
Type packages() for information about installed and available packages., 'super': , 'TypeError': , 'license': Type license() to see the full license text, 'KeyboardInterrupt': , 'UserWarning': , 'filter': , 'range': , 'staticmethod': , 'SystemError': , 'BaseException': , 'pow': , 'RuntimeError': , 'float': , 'MemoryError': , 'StopIteration': , 'globals': , 'divmod': , 'enumerate': , 'apply': , 'LookupError': , 'open': , 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'basestring': , 'UnicodeError': , 'zip': , 'hex': , 'long': , 'next': , 'ImportError': , 'chr': , 'xrange': , 'type': , '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'Exception': , 'tuple': , 'UnicodeTranslateError': , 'reversed': , 'UnicodeEncodeError': , 'IOError': , 'hasattr': , 'delattr': , 'setattr': , 'raw_input': , 'SyntaxWarning': , 'compile': , 'ArithmeticError': , 'str': , 'property': , 'GeneratorExit': , 'int': , '__import__': , 'KeyError': , 'coerce': , 'PendingDeprecationWarning': , 'file': , 'EnvironmentError': , 'unichr': , 'id': , 'OSError': , 'DeprecationWarning': , 'min': , 'UnicodeWarning': , 'execfile': , 'any': , 'complex': , 'bool': , 'ValueError': , 'NotImplemented': NotImplemented, 'map': , 'buffer': , 'max': , 'object': , 'TabError': , 'callable': , 'ZeroDivisionError': , 'eval': , '__debug__': True, 'IndentationError': , 'AssertionError': , 'classmethod': , 'UnboundLocalError': , 'NotImplementedError': , 'AttributeError': , 'OverflowError': }
316
317 # Turn off the exit flag, so the mainloop can be restarted if desired
318 self.exit_now = False
319
320 def raw_input(self, prompt=''):
321 """Write a prompt and read a line.
322
323 The returned line does not include the trailing newline.
324 When the user enters the EOF key sequence, EOFError is raised.
325
326 Optional inputs:
327
328 - prompt(''): a string to be printed to prompt the user.
329
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):
interactive.launch_ipython()