From 1ad208972c8407644d8dc69eb042dde8405a7c05 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Tue, 17 Dec 2024 01:08:13 +0530 Subject: [PATCH] clear running loop early --- Modules/_asynciomodule.c | 3 +++ Python/pystate.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index f883125a2c70b2..e7b8e5276aed2c 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3724,6 +3724,9 @@ module_clear(PyObject *mod) Py_CLEAR(state->context_kwname); + _PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET(); + Py_CLEAR(ts->asyncio_running_loop); + return 0; } diff --git a/Python/pystate.c b/Python/pystate.c index 839413a65a42fb..dfe67b95e98b27 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1667,8 +1667,6 @@ PyThreadState_Clear(PyThreadState *tstate) Py_CLEAR(tstate->threading_local_key); Py_CLEAR(tstate->threading_local_sentinel); - Py_CLEAR(((_PyThreadStateImpl *)tstate)->asyncio_running_loop); - Py_CLEAR(tstate->dict); Py_CLEAR(tstate->async_exc);