Visitar URL original
gh-128002: fix `asyncio.all_tasks` against concurrent deallocations of tasks by kumaraditya303 · Pull Request #128541 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stop the world in all tasks
  • Loading branch information
kumaraditya303 committed Jan 6, 2025
commit 687343300fdfba0dd77fb8ccda4291fc284b97f3
4 changes: 2 additions & 2 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ extern void _PyEval_StartTheWorldAll(_PyRuntimeState *runtime);
// Perform a stop-the-world pause for threads in the specified interpreter.
//
// NOTE: This is a no-op outside of Py_GIL_DISABLED builds.
extern void _PyEval_StopTheWorld(PyInterpreterState *interp);
extern void _PyEval_StartTheWorld(PyInterpreterState *interp);
extern PyAPI_FUNC(void) _PyEval_StopTheWorld(PyInterpreterState *interp);
extern PyAPI_FUNC(void) _PyEval_StartTheWorld(PyInterpreterState *interp);


static inline void
Expand Down
9 changes: 6 additions & 3 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3767,9 +3767,11 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
return NULL;
}
int err = 0;
ASYNCIO_STATE_LOCK(state);
struct llist_node *node;

PyInterpreterState *interp = PyInterpreterState_Get();
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
_PyEval_StopTheWorld(interp);

struct llist_node *node;
llist_for_each_safe(node, &state->asyncio_tasks_head) {
TaskObj *task = llist_data(node, TaskObj, task_node);
if (PyList_Append(tasks, (PyObject *)task) < 0) {
Expand All @@ -3779,7 +3781,8 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
break;
}
}
ASYNCIO_STATE_UNLOCK(state);

_PyEval_StartTheWorld(interp);
if (err) {
return NULL;
}
Expand Down