From f72dc299c432f435e310f7f5afebd868b7ca8617 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Wed, 7 Aug 2024 22:38:39 +0530 Subject: [PATCH] make _asyncio_all_tasks_impl thread safe --- Modules/_asynciomodule.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index c6eb43f044fdbd..dd2a809a834efc 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3628,6 +3628,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) Py_DECREF(item); } Py_DECREF(eager_iter); + ASYNCIO_STATE_LOCK(state); TaskObj *head = state->asyncio_tasks.head; Py_INCREF(head); assert(head != NULL); @@ -3636,6 +3637,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) while (head != tail) { if (add_one_task(state, tasks, (PyObject *)head, loop) < 0) { + ASYNCIO_STATE_UNLOCK(state); Py_DECREF(tasks); Py_DECREF(loop); Py_DECREF(head); @@ -3644,6 +3646,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) Py_INCREF(head->next); Py_SETREF(head, head->next); } + ASYNCIO_STATE_UNLOCK(state); PyObject *scheduled_iter = PyObject_GetIter(state->non_asyncio_tasks); if (scheduled_iter == NULL) { Py_DECREF(tasks);