Skip to content

Commit c53547c

Browse files
authored
gh-97696: Use PyObject_CallMethodNoArgs and inline is_loop_running check in _asyncio (#104255)
1 parent b35711d commit c53547c

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

Modules/_asynciomodule.c

+5-18
Original file line numberDiff line numberDiff line change
@@ -2063,21 +2063,6 @@ swap_current_task(asyncio_state *state, PyObject *loop, PyObject *task)
20632063
return prev_task;
20642064
}
20652065

2066-
static int
2067-
is_loop_running(PyObject *loop)
2068-
{
2069-
PyObject *func = PyObject_GetAttr(loop, &_Py_ID(is_running));
2070-
if (func == NULL) {
2071-
PyErr_Format(PyExc_TypeError, "Loop missing is_running()");
2072-
return -1;
2073-
}
2074-
PyObject *res = PyObject_CallNoArgs(func);
2075-
int retval = Py_IsTrue(res);
2076-
Py_DECREF(func);
2077-
Py_DECREF(res);
2078-
return !!retval;
2079-
}
2080-
20812066
/* ----- Task */
20822067

20832068
/*[clinic input]
@@ -2148,11 +2133,13 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
21482133
}
21492134

21502135
if (eager_start) {
2151-
int loop_running = is_loop_running(self->task_loop);
2152-
if (loop_running == -1) {
2136+
PyObject *res = PyObject_CallMethodNoArgs(loop, &_Py_ID(is_running));
2137+
if (res == NULL) {
21532138
return -1;
21542139
}
2155-
if (loop_running) {
2140+
int is_loop_running = Py_IsTrue(res);
2141+
Py_DECREF(res);
2142+
if (is_loop_running) {
21562143
if (task_eager_start(state, self)) {
21572144
return -1;
21582145
}

0 commit comments

Comments
 (0)