summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorItamar Ostricher <itamarost@gmail.com>2023-05-07 04:25:45 (GMT)
committerGitHub <noreply@github.com>2023-05-07 04:25:45 (GMT)
commitc53547c907371be53c8016145d73ba4ea0a22756 (patch)
treef7aff860b3c26def2891da7547370bce65fb33cf
parentb35711d17a90251bdd57d255090e07daafe89f6c (diff)
downloadcpython-c53547c907371be53c8016145d73ba4ea0a22756.zip
cpython-c53547c907371be53c8016145d73ba4ea0a22756.tar.gz
cpython-c53547c907371be53c8016145d73ba4ea0a22756.tar.bz2
gh-97696: Use `PyObject_CallMethodNoArgs` and inline is_loop_running check in `_asyncio` (#104255)
-rw-r--r--Modules/_asynciomodule.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 39c33fe..3830245 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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]
@@ -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;
}