|
@ -68,11 +68,13 @@ Additional functions |
|
|
.. function:: wait_for(awaitable, timeout) |
|
|
.. function:: wait_for(awaitable, timeout) |
|
|
|
|
|
|
|
|
Wait for the *awaitable* to complete, but cancel it if it takes longer |
|
|
Wait for the *awaitable* to complete, but cancel it if it takes longer |
|
|
that *timeout* seconds. If *awaitable* is not a task then a task will be |
|
|
than *timeout* seconds. If *awaitable* is not a task then a task will be |
|
|
created from it. |
|
|
created from it. |
|
|
|
|
|
|
|
|
If a timeout occurs, it cancels the task and raises ``asyncio.TimeoutError``: |
|
|
If a timeout occurs, it cancels the task and raises ``asyncio.TimeoutError``: |
|
|
this should be trapped by the caller. |
|
|
this should be trapped by the caller. The task receives |
|
|
|
|
|
``asyncio.CancelledError`` which may be ignored or trapped using ``try...except`` |
|
|
|
|
|
or ``try...finally`` to run cleanup code. |
|
|
|
|
|
|
|
|
Returns the return value of *awaitable*. |
|
|
Returns the return value of *awaitable*. |
|
|
|
|
|
|
|
@ -106,8 +108,9 @@ class Task |
|
|
|
|
|
|
|
|
.. method:: Task.cancel() |
|
|
.. method:: Task.cancel() |
|
|
|
|
|
|
|
|
Cancel the task by injecting a ``CancelledError`` into it. The task may |
|
|
Cancel the task by injecting ``asyncio.CancelledError`` into it. The task may |
|
|
or may not ignore this exception. |
|
|
ignore this exception. Cleanup code may be run by trapping it, or via |
|
|
|
|
|
``try ... finally``. |
|
|
|
|
|
|
|
|
class Event |
|
|
class Event |
|
|
----------- |
|
|
----------- |
|
|