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 <rep...@bugs.python.org>
<http://bugs.python.org/issue26637>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to