diff options
author | Guido van Rossum <guido@python.org> | 2022-10-05 06:49:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 06:49:10 (GMT) |
commit | 8079bef56f2249ecedafe0be5a6d7a120a7f3ac3 (patch) | |
tree | 728a3afbab702ee4442a12d620ccd3e390a0a0ed /Doc | |
parent | c70c8b69762f720377adaf22f2e5ec6496a7be53 (diff) | |
download | cpython-8079bef56f2249ecedafe0be5a6d7a120a7f3ac3.zip cpython-8079bef56f2249ecedafe0be5a6d7a120a7f3ac3.tar.gz cpython-8079bef56f2249ecedafe0be5a6d7a120a7f3ac3.tar.bz2 |
GH-96704: Add {Task,Handle}.get_context(), use it in call_exception_handler() (#96756)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/asyncio-eventloop.rst | 16 | ||||
-rw-r--r-- | Doc/library/asyncio-task.rst | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index c51990e..6fe9568 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1271,6 +1271,15 @@ Allows customizing how exceptions are handled in the event loop. (see :meth:`call_exception_handler` documentation for details about context). + If the handler is called on behalf of a :class:`~asyncio.Task` or + :class:`~asyncio.Handle`, it is run in the + :class:`contextvars.Context` of that task or callback handle. + + .. versionchanged:: 3.12 + + The handler may be called in the :class:`~contextvars.Context` + of the task or handle where the exception originated. + .. method:: loop.get_exception_handler() Return the current exception handler, or ``None`` if no custom @@ -1474,6 +1483,13 @@ Callback Handles A callback wrapper object returned by :meth:`loop.call_soon`, :meth:`loop.call_soon_threadsafe`. + .. method:: get_context() + + Return the :class:`contextvars.Context` object + associated with the handle. + + .. versionadded:: 3.12 + .. method:: cancel() Cancel the callback. If the callback has already been canceled diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index ade9692..d922f61 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -1097,6 +1097,13 @@ Task Object .. versionadded:: 3.8 + .. method:: get_context() + + Return the :class:`contextvars.Context` object + associated with the task. + + .. versionadded:: 3.12 + .. method:: get_name() Return the name of the Task. |