summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-12-18 14:25:03 (GMT)
committerGitHub <noreply@github.com>2024-12-18 14:25:03 (GMT)
commit8a433b683fecafe1cb04469a301df2b4618167d0 (patch)
treef5148e811bd828312d749e67a2f24896e5abb0b2 /Modules
parentdbd08fb60d1c434ebb6009d28d2b97f90e011032 (diff)
downloadcpython-8a433b683fecafe1cb04469a301df2b4618167d0.zip
cpython-8a433b683fecafe1cb04469a301df2b4618167d0.tar.gz
cpython-8a433b683fecafe1cb04469a301df2b4618167d0.tar.bz2
gh-121621: clear running loop early in asyncio (#128004)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_asynciomodule.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 13dd2fd..27c1636 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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;
}