Skip to content

Commit

Permalink
stop the world in all tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 committed Jan 6, 2025
1 parent 8d15058 commit 6873433
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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();
_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

0 comments on commit 6873433

Please sign in to comment.