diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-23 16:40:59 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-23 16:40:59 (GMT) |
commit | 421e49b5c15574264dadbf5f4020870ec0c78f51 (patch) | |
tree | ff8d643ab98377b7071b9ab02f12c2273354a738 /Lib/asyncio | |
parent | 183e3477968c5b1b003fa18926fbbca7ab96ac36 (diff) | |
download | cpython-421e49b5c15574264dadbf5f4020870ec0c78f51.zip cpython-421e49b5c15574264dadbf5f4020870ec0c78f51.tar.gz cpython-421e49b5c15574264dadbf5f4020870ec0c78f51.tar.bz2 |
asyncio: wait_for() now cancels the future on timeout. Patch written by Gustavo
Carneiro.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/tasks.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 42413dc..b52933f 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -382,8 +382,9 @@ def wait_for(fut, timeout, *, loop=None): Coroutine will be wrapped in Task. - Returns result of the Future or coroutine. Raises TimeoutError when - timeout occurs. + Returns result of the Future or coroutine. When a timeout occurs, + it cancels the task and raises TimeoutError. To avoid the task + cancellation, wrap it in shield(). Usage: @@ -405,6 +406,7 @@ def wait_for(fut, timeout, *, loop=None): return fut.result() else: fut.remove_done_callback(cb) + fut.cancel() raise futures.TimeoutError() finally: timeout_handle.cancel() |