Skip to content

Commit

Permalink
make _asyncio_all_tasks_impl thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 committed Aug 7, 2024
1 parent 967a4f1 commit f72dc29
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f72dc29

Please sign in to comment.