@@ -25,19 +25,18 @@ def runner_exception_hook(args: threading.ExceptHookArgs):
25
25
# threading.excepthook = runner_exception_hook
26
26
27
27
def as_completed (loop , coros , max_workers ):
28
+ loop_arg_dict = {"loop" : loop } if sys .version_info [:2 ] < (3 , 10 ) else {}
28
29
if max_workers == - 1 :
29
- return asyncio .as_completed (coros , loop = loop )
30
+ return asyncio .as_completed (coros , ** loop_arg_dict )
30
31
31
32
# 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 ):
37
35
async with semaphore :
38
36
return await coro
39
37
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 )
41
40
42
41
class Runner (threading .Thread ):
43
42
def __init__ (
@@ -46,7 +45,7 @@ def __init__(
46
45
desc : str ,
47
46
keep_progress_bar : bool = True ,
48
47
raise_exceptions : bool = True ,
49
- run_config : RunConfig = None ,
48
+ run_config : t . Optional [ RunConfig ] = None
50
49
):
51
50
super ().__init__ ()
52
51
self .jobs = jobs
@@ -103,7 +102,7 @@ class Executor:
103
102
keep_progress_bar : bool = True
104
103
jobs : t .List [t .Any ] = field (default_factory = list , repr = False )
105
104
raise_exceptions : bool = False
106
- run_config : RunConfig = None
105
+ run_config : t . Optional [ RunConfig ] = field ( default_factory = RunConfig , repr = False )
107
106
108
107
def wrap_callable_with_index (self , callable : t .Callable , counter ):
109
108
async def wrapped_callable_async (* args , ** kwargs ):
0 commit comments