gh-121621: clear running loop early in asyncio (#128004)

This commit is contained in:
Kumar Aditya 2024-12-18 19:55:03 +05:30 committed by GitHub
parent dbd08fb60d
commit 8a433b683f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -3723,6 +3723,11 @@ module_clear(PyObject *mod)
Py_CLEAR(state->iscoroutine_typecache); Py_CLEAR(state->iscoroutine_typecache);
Py_CLEAR(state->context_kwname); 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; return 0;
} }