cpython/Lib/asyncio
Miss Islington (bot) d8948c5e09
bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
Currently, asyncio.wait_for(fut), upon reaching the timeout deadline,
cancels the future and returns immediately.  This is problematic for
when *fut* is a Task, because it will be left running for an arbitrary
amount of time.  This behavior is iself surprising and may lead to
related bugs such as the one described in bpo-33638:

    condition = asyncio.Condition()
    async with condition:
        await asyncio.wait_for(condition.wait(), timeout=0.5)

Currently, instead of raising a TimeoutError, the above code will fail
with `RuntimeError: cannot wait on un-acquired lock`, because
`__aexit__` is reached _before_ `condition.wait()` finishes its
cancellation and re-acquires the condition lock.

To resolve this, make `wait_for` await for the task cancellation.
The tradeoff here is that the `timeout` promise may be broken if the
task decides to handle its cancellation in a slow way.  This represents
a behavior change and should probably not be back-patched to 3.6 and
earlier.
(cherry picked from commit e2b340ab41)

Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
2018-05-29 15:37:06 -07:00
..
__init__.py bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174) 2018-05-28 17:16:43 -07:00
base_events.py bpo-33674: Pause the transport as early as possible (GH-7192) 2018-05-28 22:59:03 -07:00
base_futures.py bpo-32436: Implement PEP 567 (#5027) 2018-01-22 19:11:18 -05:00
base_subprocess.py [3.7] bpo-32262: Fix typo in f-string (GH-7016) 2018-05-20 20:22:50 +02:00
base_tasks.py bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775) 2017-12-10 18:36:12 -05:00
constants.py bpo-32410: Avoid blocking on file IO in sendfile fallback code (GH-7172) (#7182) 2018-05-28 21:42:45 -04:00
coroutines.py bpo-33672: Fix Task.__repr__ crash with Cython's bogus coroutines (GH-7161) (GH-7173) 2018-05-28 18:31:07 -04:00
events.py bpo-22087: Fix Policy.get_event_loop() to detect fork (GH-7208) 2018-05-29 14:09:17 -07:00
format_helpers.py bpo-33672: Fix Task.__repr__ crash with Cython's bogus coroutines (GH-7161) (GH-7173) 2018-05-28 18:31:07 -04:00
futures.py bpo-33469: RuntimeError after closing loop that used run_in_executor (GH-7171) 2018-05-28 15:50:02 -07:00
locks.py bpo-32841: Fix cancellation in awaiting asyncio.Condition (GH-5665) 2018-02-14 01:47:30 -08:00
log.py Rename the logger to plain "logger". 2013-10-17 15:39:45 -07:00
proactor_events.py bpo-33654: Support BufferedProtocol in set_protocol() and start_tls() (GH-7130) 2018-05-28 11:50:45 -07:00
protocols.py bpo-33654: Support BufferedProtocol in set_protocol() and start_tls() (GH-7130) 2018-05-28 11:50:45 -07:00
queues.py bpo-32574: Fix leaks in asyncio.Queue.put() and .get() (#5208) 2018-01-25 18:45:43 -05:00
runners.py bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174) 2018-05-28 17:16:43 -07:00
selector_events.py bpo-33654: Support BufferedProtocol in set_protocol() and start_tls() (GH-7130) 2018-05-28 11:50:45 -07:00
sslproto.py bpo-33654: Support protocol type switching in SSLTransport.set_protocol() (GH-7194) 2018-05-29 02:19:09 -07:00
streams.py bpo-33353: test_asyncio use set_write_buffer_limits() (GH-7200) 2018-05-29 07:21:46 -07:00
subprocess.py bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775) 2017-12-10 18:36:12 -05:00
tasks.py bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216) 2018-05-29 15:37:06 -07:00
transports.py bpo-32356: idempotent pause_/resume_reading; new is_reading method. (#4914) 2017-12-18 17:03:23 -05:00
unix_events.py bpo-33654: Support BufferedProtocol in set_protocol() and start_tls() (GH-7130) 2018-05-28 11:50:45 -07:00
windows_events.py bpo-32622: Native sendfile on windows (GH-5565) 2018-02-25 09:10:58 -08:00
windows_utils.py bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775) 2017-12-10 18:36:12 -05:00