Skip to content

Commit a6373a7

Browse files
committed
gh-159303: Document the exception handler context change
1 parent c357cc2 commit a6373a7

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎Doc/library/asyncio-eventloop.rst‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,14 +1493,20 @@ Allows customizing how exceptions are handled in the event loop.
14931493
about context).
14941494

14951495
If the handler is called on behalf of a :class:`~asyncio.Task` or
1496-
:class:`~asyncio.Handle`, it is run in the
1496+
:class:`~asyncio.Handle`, it is run in a copy of the
14971497
:class:`contextvars.Context` of that task or callback handle.
14981498

14991499
.. versionchanged:: 3.12
15001500

15011501
The handler may be called in the :class:`~contextvars.Context`
15021502
of the task or handle where the exception originated.
15031503

1504+
.. versionchanged:: next
1505+
1506+
The handler now runs in a copy of that context. Previously, reporting
1507+
an exception from inside the task's own context raised
1508+
:exc:`RuntimeError` and the handler was skipped.
1509+
15041510
.. method:: loop.get_exception_handler()
15051511

15061512
Return the current exception handler, or ``None`` if no custom
@@ -1519,6 +1525,13 @@ Allows customizing how exceptions are handled in the event loop.
15191525
*context* parameter has the same meaning as in
15201526
:meth:`call_exception_handler`.
15211527

1528+
.. versionchanged:: next
1529+
1530+
When no exception handler is set, :meth:`call_exception_handler`
1531+
runs this method in a copy of the :class:`contextvars.Context` of
1532+
the task or handle where the exception originated, as for a custom
1533+
handler.
1534+
15221535
.. method:: loop.call_exception_handler(context)
15231536

15241537
Call the current event loop exception handler.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:meth:`asyncio.loop.call_exception_handler` now runs the default exception
2-
handler in the context of the task, future or handle that caused the error,
2+
handler in the context of the task or handle that caused the error,
33
as it already did for a custom exception handler. Both handlers now run in a
44
copy of that context, so reporting an error from inside the task itself no
55
longer fails with :exc:`RuntimeError`.

0 commit comments

Comments
 (0)