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 brett.cannon, eric.snow, vstinner
Date 2016-03-24.15:06:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Example of
class Bla:
    def __del__(self):
            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
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
import error: [<class 'ImportError'>] ImportError('sys.meta_path is None, Python is likely shutting down',)
Date User Action Args
2016-03-24 15:06:33vstinnersetrecipients: + vstinner, brett.cannon, eric.snow
2016-03-24 15:06:33vstinnersetmessageid: <>
2016-03-24 15:06:33vstinnerlinkissue26637 messages
2016-03-24 15:06:32vstinnercreate