@@ -25,19 +25,18 @@ def runner_exception_hook(args: threading.ExceptHookArgs):
2525# threading.excepthook = runner_exception_hook
2626
2727def as_completed (loop , coros , max_workers ):
28+ loop_arg_dict = {"loop" : loop } if sys .version_info [:2 ] < (3 , 10 ) else {}
2829 if max_workers == - 1 :
29- return asyncio .as_completed (coros , loop = loop )
30+ return asyncio .as_completed (coros , ** loop_arg_dict )
3031
3132 # loop argument is removed since Python 3.10
32- semaphore = asyncio .Semaphore (
33- max_workers ,
34- ** ({"loop" : loop } if sys .version_info [:2 ] < (3 , 10 ) else {})
35- )
36- async def sem_coro (coro ):
33+ semaphore = asyncio .Semaphore (max_workers , ** loop_arg_dict )
34+ async def sema_coro (coro ):
3735 async with semaphore :
3836 return await coro
3937
40- return asyncio .as_completed ([sem_coro (c ) for c in coros ], loop = loop )
38+ sema_coros = [sema_coro (c ) for c in coros ]
39+ return asyncio .as_completed (sema_coros , ** loop_arg_dict )
4140
4241class Runner (threading .Thread ):
4342 def __init__ (
@@ -46,7 +45,7 @@ def __init__(
4645 desc : str ,
4746 keep_progress_bar : bool = True ,
4847 raise_exceptions : bool = True ,
49- run_config : RunConfig = None ,
48+ run_config : t . Optional [ RunConfig ] = None
5049 ):
5150 super ().__init__ ()
5251 self .jobs = jobs
@@ -103,7 +102,7 @@ class Executor:
103102 keep_progress_bar : bool = True
104103 jobs : t .List [t .Any ] = field (default_factory = list , repr = False )
105104 raise_exceptions : bool = False
106- run_config : RunConfig = None
105+ run_config : t . Optional [ RunConfig ] = field ( default_factory = RunConfig , repr = False )
107106
108107 def wrap_callable_with_index (self , callable : t .Callable , counter ):
109108 async def wrapped_callable_async (* args , ** kwargs ):
0 commit comments