@@ -37,6 +37,8 @@ class Transaction:
3737
3838 verbose : bool | int = False
3939
40+ tg : asyncio .TaskGroup | None = None
41+
4042 def __post_init__ (self ):
4143 # If index_urls is None, pyodide-lock.json have to be searched first.
4244 # TODO: when PyPI starts to support hosting WASM wheels, this might be deleted.
@@ -48,21 +50,15 @@ async def gather_requirements(
4850 self ,
4951 requirements : list [str ] | list [Requirement ],
5052 ) -> 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
6662
6763 async def add_requirement (self , req : str | Requirement ) -> None :
6864 if isinstance (req , Requirement ):
0 commit comments