Skip to content

Commit ae2dcf3

Browse files
committed
Support coro_result in Task C impl
1 parent ac26ad6 commit ae2dcf3

7 files changed

+53
-15
lines changed

Include/internal/pycore_global_objects_fini_generated.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ struct _Py_global_strings {
337337
STRUCT_FOR_ID(copy)
338338
STRUCT_FOR_ID(copyreg)
339339
STRUCT_FOR_ID(coro)
340+
STRUCT_FOR_ID(coro_result)
340341
STRUCT_FOR_ID(count)
341342
STRUCT_FOR_ID(cwd)
342343
STRUCT_FOR_ID(d)

Include/internal/pycore_runtime_init_generated.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_asynciomodule.c

+29-5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ class _asyncio.Future "FutureObj *" "&Future_Type"
156156
/* Get FutureIter from Future */
157157
static PyObject * future_new_iter(PyObject *);
158158

159+
static PyObject *
160+
task_step2_impl(asyncio_state *state, TaskObj *task, PyObject *result);
161+
159162

160163
static int
161164
_is_coroutine(asyncio_state *state, PyObject *coro)
@@ -2033,15 +2036,16 @@ _asyncio.Task.__init__
20332036
loop: object = None
20342037
name: object = None
20352038
context: object = None
2039+
coro_result: object = NULL
20362040
20372041
A coroutine wrapped in a Future.
20382042
[clinic start generated code]*/
20392043

20402044
static int
20412045
_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
2042-
PyObject *name, PyObject *context)
2043-
/*[clinic end generated code: output=49ac96fe33d0e5c7 input=924522490c8ce825]*/
2044-
2046+
PyObject *name, PyObject *context,
2047+
PyObject *coro_result)
2048+
/*[clinic end generated code: output=e241855787412a77 input=3fcd7fb1c00d3f87]*/
20452049
{
20462050
if (future_init((FutureObj*)self, loop)) {
20472051
return -1;
@@ -2089,8 +2093,14 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
20892093
return -1;
20902094
}
20912095

2092-
if (task_call_step_soon(state, self, NULL)) {
2093-
return -1;
2096+
if (coro_result == NULL) {
2097+
if (task_call_step_soon(state, self, NULL)) {
2098+
return -1;
2099+
}
2100+
}
2101+
else {
2102+
Py_INCREF(coro_result);
2103+
task_step2_impl(state, self, coro_result);
20942104
}
20952105
return register_task(state, (PyObject*)self);
20962106
}
@@ -2844,6 +2854,20 @@ task_step_impl(asyncio_state *state, TaskObj *task, PyObject *exc)
28442854
Py_RETURN_NONE;
28452855
}
28462856

2857+
return task_step2_impl(state, task, result);
2858+
2859+
fail:
2860+
Py_XDECREF(result);
2861+
return NULL;
2862+
}
2863+
2864+
2865+
static PyObject *
2866+
task_step2_impl(asyncio_state *state, TaskObj *task, PyObject *result)
2867+
{
2868+
int res;
2869+
PyObject *o;
2870+
28472871
if (result == (PyObject*)task) {
28482872
/* We have a task that wants to await on itself */
28492873
goto self_await;

Modules/clinic/_asynciomodule.c.h

+18-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

async_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def counting_task_constructor(coro, *, loop=None, name=None, context=None, coro_
151151
# only count calls that will actually result a task scheduled to the event loop
152152
# (if coro_result is non-None, it will return synchronously)
153153
self.task_count += 1
154-
return asyncio.tasks._PyTask(coro, loop=loop, name=name, context=context, coro_result=coro_result)
154+
return asyncio.Task(coro, loop=loop, name=name, context=context, coro_result=coro_result)
155155

156156
def counting_task_factory(loop, coro, *, name=None, context=None, coro_result=None):
157157
return counting_task_constructor(coro, loop=loop, name=name, context=context, coro_result=coro_result)

0 commit comments

Comments
 (0)