@@ -306,9 +306,11 @@ def __init__(self,
306306 load_default_modules = True ,
307307 shell_prompt = DEFAULT_SHELL_PROMPT ,
308308 conn_cls = None ,
309- is_container = False
309+ is_container = False ,
310+ max_async = 50 ,
310311 ):
311312 self ._async_pool = None
313+ self ._async_pool_size = None
312314 self ._unused_conns = set ()
313315
314316 self ._is_rooted = None
@@ -352,7 +354,7 @@ def __init__(self,
352354 self .modules = merge_lists (* module_lists , duplicates = 'first' )
353355 self ._update_modules ('early' )
354356 if connect :
355- self .connect ()
357+ self .connect (max_async = max_async )
356358
357359 def __getstate__ (self ):
358360 # tls_property will recreate the underlying value automatically upon
@@ -363,12 +365,25 @@ def __getstate__(self):
363365 for k , v in inspect .getmembers (self .__class__ )
364366 if isinstance (v , _BoundTLSProperty )
365367 }
368+ ignored .update ((
369+ '_async_pool' ,
370+ '_unused_conns' ,
371+ ))
366372 return {
367373 k : v
368374 for k , v in self .__dict__ .items ()
369375 if k not in ignored
370376 }
371377
378+ def __setstate__ (self , dct ):
379+ self .__dict__ = dct
380+ pool_size = self ._async_pool_size
381+ if pool_size is None :
382+ self ._async_pool = None
383+ else :
384+ self ._async_pool = ThreadPoolExecutor (pool_size )
385+ self ._unused_conns = set ()
386+
372387 # connection and initialization
373388
374389 @asyn .asyncf
@@ -433,6 +448,7 @@ def make_conn(_):
433448 max_conns = len (conns )
434449
435450 self .logger .debug (f'Detected max number of async commands: { max_conns } ' )
451+ self ._async_pool_size = max_conns
436452 self ._async_pool = ThreadPoolExecutor (max_conns )
437453
438454 @asyn .asyncf
@@ -1547,6 +1563,7 @@ def __init__(self,
15471563 shell_prompt = DEFAULT_SHELL_PROMPT ,
15481564 conn_cls = SshConnection ,
15491565 is_container = False ,
1566+ max_async = 50 ,
15501567 ):
15511568 super (LinuxTarget , self ).__init__ (connection_settings = connection_settings ,
15521569 platform = platform ,
@@ -1557,7 +1574,8 @@ def __init__(self,
15571574 load_default_modules = load_default_modules ,
15581575 shell_prompt = shell_prompt ,
15591576 conn_cls = conn_cls ,
1560- is_container = is_container )
1577+ is_container = is_container ,
1578+ max_async = max_async )
15611579
15621580 def wait_boot_complete (self , timeout = 10 ):
15631581 pass
@@ -1752,6 +1770,7 @@ def __init__(self,
17521770 conn_cls = AdbConnection ,
17531771 package_data_directory = "/data/data" ,
17541772 is_container = False ,
1773+ max_async = 50 ,
17551774 ):
17561775 super (AndroidTarget , self ).__init__ (connection_settings = connection_settings ,
17571776 platform = platform ,
@@ -1762,7 +1781,8 @@ def __init__(self,
17621781 load_default_modules = load_default_modules ,
17631782 shell_prompt = shell_prompt ,
17641783 conn_cls = conn_cls ,
1765- is_container = is_container )
1784+ is_container = is_container ,
1785+ max_async = max_async )
17661786 self .package_data_directory = package_data_directory
17671787 self ._init_logcat_lock ()
17681788
@@ -2823,6 +2843,7 @@ def __init__(self,
28232843 shell_prompt = DEFAULT_SHELL_PROMPT ,
28242844 conn_cls = LocalConnection ,
28252845 is_container = False ,
2846+ max_async = 50 ,
28262847 ):
28272848 super (LocalLinuxTarget , self ).__init__ (connection_settings = connection_settings ,
28282849 platform = platform ,
@@ -2833,7 +2854,8 @@ def __init__(self,
28332854 load_default_modules = load_default_modules ,
28342855 shell_prompt = shell_prompt ,
28352856 conn_cls = conn_cls ,
2836- is_container = is_container )
2857+ is_container = is_container ,
2858+ max_async = max_async )
28372859
28382860 def _resolve_paths (self ):
28392861 if self .working_directory is None :
@@ -2906,7 +2928,8 @@ def __init__(self,
29062928 load_default_modules = True ,
29072929 shell_prompt = DEFAULT_SHELL_PROMPT ,
29082930 package_data_directory = "/data/data" ,
2909- is_container = False
2931+ is_container = False ,
2932+ max_async = 50 ,
29102933 ):
29112934
29122935 self .supports_android = None
@@ -2932,7 +2955,8 @@ def __init__(self,
29322955 load_default_modules = load_default_modules ,
29332956 shell_prompt = shell_prompt ,
29342957 conn_cls = SshConnection ,
2935- is_container = is_container )
2958+ is_container = is_container ,
2959+ max_async = max_async )
29362960
29372961 # We can't determine if the target supports android until connected to the linux host so
29382962 # create unconditionally.
0 commit comments