Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d579742

Browse files
committed
asyncio.docs: Document Error Handling API and asyncio.Handle
1 parent aabc131 commit d579742

1 file changed

Lines changed: 67 additions & 2 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ Calls
142142
Any positional arguments after the callback will be passed to the
143143
callback when it is called.
144144

145+
An instance of :class:`asyncio.Handle` is returned.
146+
145147
.. method:: BaseEventLoop.call_soon_threadsafe(callback, \*args)
146148

147149
Like :meth:`call_soon`, but thread safe.
@@ -167,8 +169,7 @@ a different clock than :func:`time.time`.
167169
Arrange for the *callback* to be called after the given *delay*
168170
seconds (either an int or float).
169171

170-
A "handle" is returned: an opaque object with a :meth:`cancel` method
171-
that can be used to cancel the call.
172+
An instance of :class:`asyncio.Handle` is returned.
172173

173174
*callback* will be called exactly once per call to :meth:`call_later`.
174175
If two callbacks are scheduled for exactly the same time, it is
@@ -553,6 +554,56 @@ pool of processes). By default, an event loop uses a thread pool executor
553554
Set the default executor used by :meth:`run_in_executor`.
554555

555556

557+
Error Handling API
558+
------------------
559+
560+
Allows to customize how exceptions are handled in the event loop.
561+
562+
.. method:: BaseEventLoop.set_exception_handler(handler)
563+
564+
Set *handler* as the new event loop exception handler.
565+
566+
If *handler* is ``None``, the default exception handler will
567+
be set.
568+
569+
If *handler* is a callable object, it should have a
570+
matching signature to ``(loop, context)``, where ``loop``
571+
will be a reference to the active event loop, ``context``
572+
will be a ``dict`` object (see :meth:`call_exception_handler`
573+
documentation for details about context).
574+
575+
.. method:: BaseEventLoop.default_exception_handler(context)
576+
577+
Default exception handler.
578+
579+
This is called when an exception occurs and no exception
580+
handler is set, and can be called by a custom exception
581+
handler that wants to defer to the default behavior.
582+
583+
*context* parameter has the same meaning as in
584+
:meth:`call_exception_handler`.
585+
586+
.. method:: BaseEventLoop.call_exception_handler(context)
587+
588+
Call the current event loop exception handler.
589+
590+
*context* is a ``dict`` object containing the following keys
591+
(new keys may be introduced later):
592+
593+
* 'message': Error message;
594+
* 'exception' (optional): Exception object;
595+
* 'future' (optional): :class:`asyncio.Future` instance;
596+
* 'handle' (optional): :class:`asyncio.Handle` instance;
597+
* 'protocol' (optional): :ref:`Protocol <asyncio-protocol>` instance;
598+
* 'transport' (optional): :ref:`Transport <asyncio-transport>` instance;
599+
* 'socket' (optional): :class:`socket.socket` instance.
600+
601+
.. note::
602+
603+
Note: this method should not be overloaded in subclassed
604+
event loops. For any custom exception handling, use
605+
:meth:`set_exception_handler()` method.
606+
556607
Debug mode
557608
----------
558609

@@ -585,6 +636,20 @@ Server
585636
Coroutine to wait until service is closed.
586637

587638

639+
Handle
640+
------
641+
642+
.. class:: Handle
643+
644+
A callback wrapper object returned by :func:`BaseEventLoop.call_soon`,
645+
:func:`BaseEventLoop.call_soon_threadsafe`, :func:`BaseEventLoop.call_later`,
646+
and :func:`BaseEventLoop.call_at`.
647+
648+
.. method:: cancel()
649+
650+
Cancel the call.
651+
652+
588653
.. _asyncio-hello-world-callback:
589654

590655
Example: Hello World (callback)

0 commit comments

Comments
 (0)