[New-bugs-announce] [issue22599] traceback: errors in the linecache module at exit

STINNER Victor report at bugs.python.org
Fri Oct 10 13:36:01 CEST 2014

New submission from STINNER Victor:

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

components: Library (Lib)
files: destructortest.py
messages: 228986
nosy: haypo
priority: normal
severity: normal
status: open
title: traceback: errors in the linecache module at exit
versions: Python 3.5
Added file: http://bugs.python.org/file36863/destructortest.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list