summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/utils.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-21 19:48:53 (GMT)
committerGitHub <noreply@github.com>2023-10-21 19:48:53 (GMT)
commit028f47754c78864abf6eb1930493871727925b6a (patch)
treed60711f8529ac9acf1025780d27e392921b7dad0 /Lib/test/test_asyncio/utils.py
parent322f79f5a2c47507b881e868071c078c343d4301 (diff)
downloadcpython-028f47754c78864abf6eb1930493871727925b6a.zip
cpython-028f47754c78864abf6eb1930493871727925b6a.tar.gz
cpython-028f47754c78864abf6eb1930493871727925b6a.tar.bz2
[3.12] gh-111085: Fix invalid state handling in TaskGroup and Timeout (GH-111111) (GH-111171)
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 6c23635f2b7067ef091a550954e09f8b7c329e3f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
Diffstat (limited to 'Lib/test/test_asyncio/utils.py')
-rw-r--r--Lib/test/test_asyncio/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index 8d44717..9e8fe2a 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -613,3 +613,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