Eric Snow <ericsnowcurren...@gmail.com> added the comment:
I've changed the issue title to reflect where things stand. Hmm, doing so reminded me of an important consideration here. A module object is effectively a fairly light wrapper around a dict. When you call importlib.reload() the loader from the module's spec is used to re-execute the module's existing dict. [1][2] A new module is not created and the existing module namespace is not reset. So during reload the module is responsible for deleting anything in its namespace that wouldn't get replaced when re-executed (including attributes that were added to the namespace externally). For most modules this isn't an issue. However, it's something to consider when reloading a module. See the docs for more explanation and caveats. [3] [1] https://github.com/python/cpython/blob/master/Lib/importlib/__init__.py#L169 [2] https://github.com/python/cpython/blob/master/Lib/importlib/_bootstrap.py#L610 [3] https://docs.python.org/3/library/importlib.html#importlib.reload ---------- title: Embedding Python; Py_Initialize / Py_Finalize cycles -> Trouble when reloading extension modules. _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34309> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com