Skip to content

Commit 8a433b6

Browse files
gh-121621: clear running loop early in asyncio (#128004)
1 parent dbd08fb commit 8a433b6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Modules/_asynciomodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,11 @@ module_clear(PyObject *mod)
37233723
Py_CLEAR(state->iscoroutine_typecache);
37243724

37253725
Py_CLEAR(state->context_kwname);
3726+
// Clear the ref to running loop so that finalizers can run early.
3727+
// If there are other running loops in different threads,
3728+
// those get cleared in PyThreadState_Clear.
3729+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
3730+
Py_CLEAR(ts->asyncio_running_loop);
37263731

37273732
return 0;
37283733
}

0 commit comments

Comments
 (0)