]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121621: clear running loop early in asyncio (#128004)
authorKumar Aditya <kumaraditya@python.org>
Wed, 18 Dec 2024 14:25:03 +0000 (19:55 +0530)
committerGitHub <noreply@github.com>
Wed, 18 Dec 2024 14:25:03 +0000 (14:25 +0000)
Modules/_asynciomodule.c

index 13dd2fd55fd4541f986879f5b9035aa8ddcbf65a..27c163644573365379927581a6b921131afaea49 100644 (file)
@@ -3723,6 +3723,11 @@ module_clear(PyObject *mod)
     Py_CLEAR(state->iscoroutine_typecache);
 
     Py_CLEAR(state->context_kwname);
+    // Clear the ref to running loop so that finalizers can run early.
+    // If there are other running loops in different threads,
+    // those get cleared in PyThreadState_Clear.
+    _PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
+    Py_CLEAR(ts->asyncio_running_loop);
 
     return 0;
 }