Skip to content

Commit

Permalink
Support coro_result in Task C impl
Browse files Browse the repository at this point in the history
  • Loading branch information
itamaro committed Feb 11, 2023
1 parent ac26ad6 commit fa7c13e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(copy)
STRUCT_FOR_ID(copyreg)
STRUCT_FOR_ID(coro)
STRUCT_FOR_ID(coro_result)
STRUCT_FOR_ID(count)
STRUCT_FOR_ID(cwd)
STRUCT_FOR_ID(d)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2033,15 +2033,16 @@ _asyncio.Task.__init__
loop: object = None
name: object = None
context: object = None
coro_result: object = None
A coroutine wrapped in a Future.
[clinic start generated code]*/

static int
_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
PyObject *name, PyObject *context)
/*[clinic end generated code: output=49ac96fe33d0e5c7 input=924522490c8ce825]*/

PyObject *name, PyObject *context,
PyObject *coro_result)
/*[clinic end generated code: output=e241855787412a77 input=56034b36df8d270d]*/
{
if (future_init((FutureObj*)self, loop)) {
return -1;
Expand Down Expand Up @@ -2089,8 +2090,10 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
return -1;
}

if (task_call_step_soon(state, self, NULL)) {
return -1;
if (!Py_IsNone(coro_result)) {
if (task_call_step_soon(state, self, NULL)) {
return -1;
}
}
return register_task(state, (PyObject*)self);
}
Expand Down
26 changes: 17 additions & 9 deletions Modules/clinic/_asynciomodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion async_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def counting_task_constructor(coro, *, loop=None, name=None, context=None, coro_
# only count calls that will actually result a task scheduled to the event loop
# (if coro_result is non-None, it will return synchronously)
self.task_count += 1
return asyncio.tasks._PyTask(coro, loop=loop, name=name, context=context, coro_result=coro_result)
return asyncio.Task(coro, loop=loop, name=name, context=context, coro_result=coro_result)

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

0 comments on commit fa7c13e

Please sign in to comment.