Author vstinner
Recipients vstinner
Date 2014-10-10.11:36:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Attached script comes the issue #22480. It calls traceback.print_exception() at exit. The problem is that the call occurs late during Python finalization. The object was stored in the namespace of the main module. Currently, Python deletes builtin functions and then deletes modules (in a random order?).

Since the traceback module is used to display errors, it's annoying to get errors in the traceback module :-) I see two options to fix the specific issue of

* Ignore exceptions while calling linecache
* Detect Python finalization and don't try to use the linecache module in this case

Attached patch implements the second option. I'm not sure that it's the best one. It includes an unit test.

Depending on the option, we can fix the issue only in Python 3.5, or fix Python 2.7, 3.4 and 3.5.

Current output:
Traceback (most recent call last):
Exception ignored in: <bound method PrintExceptionAtExit.__del__ of <__main__.PrintExceptionAtExit object at 0x7f70b84ac878>>
Traceback (most recent call last):
  File "", line 15, in __del__
  File "/home/haypo/prog/python/default/Lib/", line 169, in print_exception
  File "/home/haypo/prog/python/default/Lib/", line 153, in _format_exception_iter
  File "/home/haypo/prog/python/default/Lib/", line 18, in _format_list_iter
  File "/home/haypo/prog/python/default/Lib/", line 65, in _extract_tb_or_stack_iter
  File "/home/haypo/prog/python/default/Lib/", line 15, in getline
  File "/home/haypo/prog/python/default/Lib/", line 41, in getlines
  File "/home/haypo/prog/python/default/Lib/", line 126, in updatecache
  File "/home/haypo/prog/python/default/Lib/", line 438, in open
AttributeError: module 'builtins' has no attribute 'open'

Expected output:
Traceback (most recent call last):
  File "", line 7, in __init__
ZeroDivisionError: division by zero
Date User Action Args
2014-10-10 11:36:01vstinnersetrecipients: + vstinner
2014-10-10 11:36:01vstinnersetmessageid: <>
2014-10-10 11:36:01vstinnerlinkissue22599 messages
2014-10-10 11:36:01vstinnercreate