summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/taskgroups.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-21 19:40:07 (GMT)
committerGitHub <noreply@github.com>2023-10-21 19:40:07 (GMT)
commitcf777399a93f837bca623e8cf887fc0ec42340e6 (patch)
tree29540861be7da307478a9e802fc8107d172e24d5 /Lib/asyncio/taskgroups.py
parentcf28c61c73174638b7596d9fff70f3c4e4965b30 (diff)
downloadcpython-cf777399a93f837bca623e8cf887fc0ec42340e6.zip
cpython-cf777399a93f837bca623e8cf887fc0ec42340e6.tar.gz
cpython-cf777399a93f837bca623e8cf887fc0ec42340e6.tar.bz2
[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 6c23635f2b7067ef091a550954e09f8b7c329e3f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
Diffstat (limited to 'Lib/asyncio/taskgroups.py')
-rw-r--r--Lib/asyncio/taskgroups.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 0fdea36..bfdbe63 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -54,16 +54,14 @@ class TaskGroup:
async def __aenter__(self):
if self._entered:
raise RuntimeError(
- f"TaskGroup {self!r} has been already entered")
- self._entered = True
-
+ f"TaskGroup {self!r} has already been entered")
if self._loop is None:
self._loop = events.get_running_loop()
-
self._parent_task = tasks.current_task(self._loop)
if self._parent_task is None:
raise RuntimeError(
f'TaskGroup {self!r} cannot determine the parent task')
+ self._entered = True
return self