[issue42671] Make the Python finalization more deterministic

Serhiy Storchaka report at bugs.python.org
Fri Dec 18 02:36:43 EST 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

I experimented with different approaches last evening. Just changing the order of clearing the module dict does not help your first example, because the __main__ module is garbage collected, but its dict is not cleared. Adding _PyModule_ClearDict() in tp_dealloc and tp_clear helps with that example, but it causes several failures and crashes in tests. I have found issue7140 and issue18214 for not clearing module dicts.

So in conclusion, your approach may work. It clears dicts of all modules, but only at shutdown. It did not worked before, when the order of dicts was undetermined, but now we can utilize deterministic order of sys.modules and module dicts.

----------
nosy: +eric.snow, pitrou

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42671>
_______________________________________


More information about the Python-bugs-list mailing list