This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2014-10-10.11:36:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1412940961.34.0.0781587147709.issue22599@psf.upfronthosting.co.za>
In-reply-to
Content
Attached destructortest.py 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 destructortest.py:

* 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 "destructortest.py", line 15, in __del__
  File "/home/haypo/prog/python/default/Lib/traceback.py", line 169, in print_exception
  File "/home/haypo/prog/python/default/Lib/traceback.py", line 153, in _format_exception_iter
  File "/home/haypo/prog/python/default/Lib/traceback.py", line 18, in _format_list_iter
  File "/home/haypo/prog/python/default/Lib/traceback.py", line 65, in _extract_tb_or_stack_iter
  File "/home/haypo/prog/python/default/Lib/linecache.py", line 15, in getline
  File "/home/haypo/prog/python/default/Lib/linecache.py", line 41, in getlines
  File "/home/haypo/prog/python/default/Lib/linecache.py", line 126, in updatecache
  File "/home/haypo/prog/python/default/Lib/tokenize.py", line 438, in open
AttributeError: module 'builtins' has no attribute 'open'
---

Expected output:
---
Traceback (most recent call last):
  File "destructortest.py", line 7, in __init__
ZeroDivisionError: division by zero
---
History
Date User Action Args
2014-10-10 11:36:01vstinnersetrecipients: + vstinner
2014-10-10 11:36:01vstinnersetmessageid: <1412940961.34.0.0781587147709.issue22599@psf.upfronthosting.co.za>
2014-10-10 11:36:01vstinnerlinkissue22599 messages
2014-10-10 11:36:01vstinnercreate