Skip to content
This repository

ipython crashes if atexit handler raises exception #207

Closed
gerritholl opened this Issue · 2 comments

2 participants

gerritholl Min RK
gerritholl

See below. I think IPython should not crash when an unhandles exception is raised in the exit-handler. It would be better to give a warning or so.

In [4]: def foo(): 1/0
   ...: 

In [5]: import atexit

In [6]: atexit.register(foo)
Out[6]: 

In [7]: exit()
Do you really want to exit ([y]/n)? y
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "", line 1, in foo
ZeroDivisionError: integer division or modulo by zero
Error in sys.exitfunc:
---------------------------------------------------------------------------
ZeroDivisionError                             Python 2.6.5: /usr/bin/python
                                                   Sun Nov 28 16:17:50 2010
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.

/usr/lib/python2.6/atexit.pyc in _run_exitfuncs()
      9 
     10 import sys
     11 
     12 _exithandlers = []
     13 def _run_exitfuncs():
     14     """run any registered exit functions
     15 
     16     _exithandlers is traversed in reverse order so functions are executed
     17     last in, first out.
     18     """
     19 
     20     exc_info = None
     21     while _exithandlers:
     22         func, targs, kargs = _exithandlers.pop()
     23         try:
---> 24             func(*targs, **kargs)
        func = >
        global function = undefined
        global to = undefined
        global be = undefined
        global called = undefined
        global at = undefined
        global exit = undefined
     25         except SystemExit:
     26             exc_info = sys.exc_info()
     27         except:
     28             import traceback
     29             print >> sys.stderr, "Error in atexit._run_exitfuncs:"
     30             traceback.print_exc()
     31             exc_info = sys.exc_info()
     32 
     33     if exc_info is not None:
     34         raise exc_info[0], exc_info[1], exc_info[2]
     35 
     36 
     37 def register(func, *targs, **kargs):
     38     """register a function to be executed upon normal program termination
     39 

/home/gerrit/ in foo()
----> 1 
      2 
      3 
      4 
      5 
      6 
      7 
      8 
      9 
     10 
     11 
     12 
     13 
     14 
     15 
     16 
     17 
     18 
     19 
     20 
     21 
     22 
     23 
     24 
     25 
     26 
     27 
     28 
     29 
     30 
     31 

ZeroDivisionError: integer division or modulo by zero

**********************************************************************

Oops, IPython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current IPython configuration.

It was left in the file named:
        '/home/gerrit/.ipython/IPython_crash_report.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: Fernando Perez at fperez.net@gmail.com
with the subject 'IPython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'IPython Crash Report' fperez.net@gmail.com 
Min RK
Owner

This is fixable by IPython unregistering its exception handler at the start of the atexit calls.

Min RK minrk referenced this issue from a commit in minrk/ipython
Min RK prevent atexit handlers from generating crash report
register `sys.excepthook = sys.__excepthook__` with atexit on aplication startup,
so it should be the first handler called.  This removes the crash handler.

closes #207
d5548fa
Min RK
Owner

closed by #876

Min RK minrk closed this
Brian E. Granger ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
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.