[New-bugs-announce] [issue26637] importlib: better error message when import fail during Python shutdown
STINNER Victor
report at bugs.python.org
Thu Mar 24 11:06:33 EDT 2016
New submission from STINNER Victor:
Example of script.py:
-------------------------
class Bla:
def __del__(self):
try:
import xxxx
except Exception as exc:
print("import error: [%s] %r" % (type(exc), exc))
bla = Bla()
-------------------------
Running this example logs a strange error:
-------------------------
$ python3.5 script.py
import error: [<class 'TypeError'>] TypeError("'NoneType' object is not iterable",)
-------------------------
The error comes from importlib._bootstrap._find_spec() which tries to iterator on sys.meta_path, whereas PyImport_Cleanup() was called and this function setted sys.meta_path to None.
Attached patch enhances _find_spec() to handle this case to return None. Error with the patch:
-------------------------
$ python3.5 script.py
import error: [<class 'ImportError'>] ImportError('sys.meta_path is None, Python is likely shutting down',)
-------------------------
----------
components: Library (Lib)
files: importlib_shutdown.patch
keywords: patch
messages: 262352
nosy: brett.cannon, eric.snow, haypo
priority: normal
severity: normal
status: open
title: importlib: better error message when import fail during Python shutdown
versions: Python 2.7, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file42275/importlib_shutdown.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26637>
_______________________________________
More information about the New-bugs-announce
mailing list