mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
[3.11] gh-111085: Fix invalid state handling in TaskGroup and Timeout (GH-111111) (GH-111172)
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.
* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
sequentially).
* If there is no current task when entering the context manager.
They now remain in a consistent state after an exception is thrown,
so subsequent operations can be performed correctly (if they are allowed).
(cherry picked from commit 6c23635f2b
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
This commit is contained in:
parent
cf28c61c73
commit
cf777399a9
6 changed files with 121 additions and 10 deletions
|
@ -612,3 +612,18 @@ def mock_nonblocking_socket(proto=socket.IPPROTO_TCP, type=socket.SOCK_STREAM,
|
|||
sock.family = family
|
||||
sock.gettimeout.return_value = 0.0
|
||||
return sock
|
||||
|
||||
|
||||
async def await_without_task(coro):
|
||||
exc = None
|
||||
def func():
|
||||
try:
|
||||
for _ in coro.__await__():
|
||||
pass
|
||||
except BaseException as err:
|
||||
nonlocal exc
|
||||
exc = err
|
||||
asyncio.get_running_loop().call_soon(func)
|
||||
await asyncio.sleep(0)
|
||||
if exc is not None:
|
||||
raise exc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue