Staging
v0.5.1
https://github.com/python/cpython
Revision d8948c5e09c4a2a818f6f6cfaf8064f2c2138fa5 authored by Miss Islington (bot) on 29 May 2018, 22:37:06 UTC, committed by GitHub on 29 May 2018, 22:37:06 UTC

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 e2b340ab4196e1beb902327f503574b5d7369185)

Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
1 parent 0364342
History
Tip revision: d8948c5e09c4a2a818f6f6cfaf8064f2c2138fa5 authored by Miss Islington (bot) on 29 May 2018, 22:37:06 UTC
bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
Tip revision: d8948c5
File Mode Size
.github
.vsts
Doc
Grammar
Include
Lib
Mac
Misc
Modules
Objects
PC
PCbuild
Parser
Programs
Python
Tools
m4
.gitattributes -rw-r--r-- 772 bytes
.gitignore -rw-r--r-- 1.5 KB
.travis.yml -rw-r--r-- 5.7 KB
LICENSE -rw-r--r-- 12.5 KB
Makefile.pre.in -rw-r--r-- 61.1 KB
README.rst -rw-r--r-- 9.3 KB
aclocal.m4 -rw-r--r-- 10.7 KB
config.guess -rwxr-xr-x 43.1 KB
config.sub -rwxr-xr-x 35.4 KB
configure -rwxr-xr-x 484.3 KB
configure.ac -rw-r--r-- 161.4 KB
install-sh -rwxr-xr-x 7.0 KB
pyconfig.h.in -rw-r--r-- 42.2 KB
setup.py -rw-r--r-- 99.5 KB

README.rst

back to top