@@ -37,6 +37,8 @@ class Transaction:
37
37
38
38
verbose : bool | int = False
39
39
40
+ tg : asyncio .TaskGroup | None = None
41
+
40
42
def __post_init__ (self ):
41
43
# If index_urls is None, pyodide-lock.json have to be searched first.
42
44
# TODO: when PyPI starts to support hosting WASM wheels, this might be deleted.
@@ -48,21 +50,15 @@ async def gather_requirements(
48
50
self ,
49
51
requirements : list [str ] | list [Requirement ],
50
52
) -> None :
51
- requirement_promises = []
52
- for requirement in requirements :
53
- requirement_promises .append (self .add_requirement (requirement ))
54
-
55
- futures : list [asyncio .Future ] = []
56
- try :
57
- for coro in requirement_promises :
58
- futures .append (asyncio .ensure_future (coro ))
59
- await asyncio .gather (* futures )
60
- except ValueError :
61
- if not self .keep_going :
62
- for future in futures :
63
- if not future .done ():
64
- future .cancel ()
65
- raise
53
+ if self .tg :
54
+ for requirement in requirements :
55
+ self .tg .create_task (self .add_requirement (requirement ))
56
+ else :
57
+ async with asyncio .TaskGroup () as tg :
58
+ self .tg = tg # only one task group from the top level
59
+ for requirement in requirements :
60
+ tg .create_task (self .add_requirement (requirement ))
61
+ self .tg = None
66
62
67
63
async def add_requirement (self , req : str | Requirement ) -> None :
68
64
if isinstance (req , Requirement ):
0 commit comments