diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2022-03-14 11:54:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 11:54:13 (GMT) |
commit | 9523c0d84f351a610dc651b234461eb015fa3b82 (patch) | |
tree | 5f6f6bed4353eb9c149f65ab2dc95db12d378db3 /Modules/_asynciomodule.c | |
parent | 2153daf0a02a598ed5df93f2f224c1ab2a2cca0d (diff) | |
download | cpython-9523c0d84f351a610dc651b234461eb015fa3b82.zip cpython-9523c0d84f351a610dc651b234461eb015fa3b82.tar.gz cpython-9523c0d84f351a610dc651b234461eb015fa3b82.tar.bz2 |
bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API (GH-31837)
Diffstat (limited to 'Modules/_asynciomodule.c')
-rw-r--r-- | Modules/_asynciomodule.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 2a6c0b3..4b12744 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -2003,14 +2003,16 @@ _asyncio.Task.__init__ * loop: object = None name: object = None + context: 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) -/*[clinic end generated code: output=88b12b83d570df50 input=352a3137fe60091d]*/ + PyObject *name, PyObject *context) +/*[clinic end generated code: output=49ac96fe33d0e5c7 input=924522490c8ce825]*/ + { if (future_init((FutureObj*)self, loop)) { return -1; @@ -2028,9 +2030,13 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, return -1; } - Py_XSETREF(self->task_context, PyContext_CopyCurrent()); - if (self->task_context == NULL) { - return -1; + if (context == Py_None) { + Py_XSETREF(self->task_context, PyContext_CopyCurrent()); + if (self->task_context == NULL) { + return -1; + } + } else { + self->task_context = Py_NewRef(context); } Py_CLEAR(self->task_fut_waiter); |