Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-97696: Use PyObject_CallMethodNoArgs and inline is_loop_running check #104255

Merged
merged 1 commit into from
May 7, 2023
Merged
Changes from all commits
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
23 changes: 5 additions & 18 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2063,21 +2063,6 @@ swap_current_task(asyncio_state *state, PyObject *loop, PyObject *task)
return prev_task;
}

static int
is_loop_running(PyObject *loop)
{
PyObject *func = PyObject_GetAttr(loop, &_Py_ID(is_running));
if (func == NULL) {
PyErr_Format(PyExc_TypeError, "Loop missing is_running()");
return -1;
}
PyObject *res = PyObject_CallNoArgs(func);
int retval = Py_IsTrue(res);
Py_DECREF(func);
Py_DECREF(res);
return !!retval;
}

/* ----- Task */

/*[clinic input]
Expand Down Expand Up @@ -2148,11 +2133,13 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
}

if (eager_start) {
int loop_running = is_loop_running(self->task_loop);
if (loop_running == -1) {
PyObject *res = PyObject_CallMethodNoArgs(loop, &_Py_ID(is_running));
if (res == NULL) {
return -1;
}
if (loop_running) {
int is_loop_running = Py_IsTrue(res);
Py_DECREF(res);
if (is_loop_running) {
if (task_eager_start(state, self)) {
return -1;
}
Expand Down