33
44__all__ = ["TaskGroup" ]
55
6- import asyncio
76import itertools
87import textwrap
98import traceback
109import types
1110import weakref
1211
12+ from . import events
13+ from . import exceptions
14+ from . import tasks
1315
1416class TaskGroup :
1517
@@ -56,9 +58,9 @@ async def __aenter__(self):
5658 self ._entered = True
5759
5860 if self ._loop is None :
59- self ._loop = asyncio .get_running_loop ()
61+ self ._loop = events .get_running_loop ()
6062
61- self ._parent_task = asyncio .current_task (self ._loop )
63+ self ._parent_task = tasks .current_task (self ._loop )
6264 if self ._parent_task is None :
6365 raise RuntimeError (
6466 f'TaskGroup { self !r} cannot determine the parent task' )
@@ -74,7 +76,7 @@ async def __aexit__(self, et, exc, tb):
7476 self ._base_error is None ):
7577 self ._base_error = exc
7678
77- if et is asyncio .CancelledError :
79+ if et is exceptions .CancelledError :
7880 if self ._parent_cancel_requested :
7981 # Only if we did request task to cancel ourselves
8082 # we mark it as no longer cancelled.
@@ -89,7 +91,7 @@ async def __aexit__(self, et, exc, tb):
8991 # g.create_task(...)
9092 # await ... # <- CancelledError
9193 #
92- if et is asyncio .CancelledError :
94+ if et is exceptions .CancelledError :
9395 propagate_cancellation_error = et
9496
9597 # or there's an exception in "async with":
@@ -110,7 +112,7 @@ async def __aexit__(self, et, exc, tb):
110112
111113 try :
112114 await self ._on_completed_fut
113- except asyncio .CancelledError as ex :
115+ except exceptions .CancelledError as ex :
114116 if not self ._aborting :
115117 # Our parent task is being cancelled:
116118 #
@@ -137,7 +139,7 @@ async def __aexit__(self, et, exc, tb):
137139 # request now.
138140 raise propagate_cancellation_error
139141
140- if et is not None and et is not asyncio .CancelledError :
142+ if et is not None and et is not exceptions .CancelledError :
141143 self ._errors .append (exc )
142144
143145 if self ._errors :
0 commit comments