mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
bpo-33331: Clean modules in the reversed order in PyImport_Cleanup(). (GH-6565)
Modules imported last are now cleared first at interpreter shutdown. A newly imported module is moved to the end of sys.modules, behind modules on which it depends.
This commit is contained in:
parent
542497aa9f
commit
c93c58b5d5
4 changed files with 1818 additions and 1850 deletions
|
@ -543,9 +543,10 @@ PyImport_Cleanup(void)
|
|||
module last. Likewise, we don't delete sys until the very
|
||||
end because it is implicitly referenced (e.g. by print). */
|
||||
if (weaklist != NULL) {
|
||||
Py_ssize_t i, n;
|
||||
n = PyList_GET_SIZE(weaklist);
|
||||
for (i = 0; i < n; i++) {
|
||||
Py_ssize_t i;
|
||||
/* Since dict is ordered in CPython 3.6+, modules are saved in
|
||||
importing order. First clear modules imported later. */
|
||||
for (i = PyList_GET_SIZE(weaklist) - 1; i >= 0; i--) {
|
||||
PyObject *tup = PyList_GET_ITEM(weaklist, i);
|
||||
PyObject *name = PyTuple_GET_ITEM(tup, 0);
|
||||
PyObject *mod = PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup, 1));
|
||||
|
|
3542
Python/importlib.h
generated
3542
Python/importlib.h
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue