@@ -306,9 +306,11 @@ def __init__(self,
306
306
load_default_modules = True ,
307
307
shell_prompt = DEFAULT_SHELL_PROMPT ,
308
308
conn_cls = None ,
309
- is_container = False
309
+ is_container = False ,
310
+ max_async = 50 ,
310
311
):
311
312
self ._async_pool = None
313
+ self ._async_pool_size = None
312
314
self ._unused_conns = set ()
313
315
314
316
self ._is_rooted = None
@@ -352,7 +354,7 @@ def __init__(self,
352
354
self .modules = merge_lists (* module_lists , duplicates = 'first' )
353
355
self ._update_modules ('early' )
354
356
if connect :
355
- self .connect ()
357
+ self .connect (max_async = max_async )
356
358
357
359
def __getstate__ (self ):
358
360
# tls_property will recreate the underlying value automatically upon
@@ -363,12 +365,25 @@ def __getstate__(self):
363
365
for k , v in inspect .getmembers (self .__class__ )
364
366
if isinstance (v , _BoundTLSProperty )
365
367
}
368
+ ignored .update ((
369
+ '_async_pool' ,
370
+ '_unused_conns' ,
371
+ ))
366
372
return {
367
373
k : v
368
374
for k , v in self .__dict__ .items ()
369
375
if k not in ignored
370
376
}
371
377
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
+
372
387
# connection and initialization
373
388
374
389
@asyn .asyncf
@@ -433,6 +448,7 @@ def make_conn(_):
433
448
max_conns = len (conns )
434
449
435
450
self .logger .debug (f'Detected max number of async commands: { max_conns } ' )
451
+ self ._async_pool_size = max_conns
436
452
self ._async_pool = ThreadPoolExecutor (max_conns )
437
453
438
454
@asyn .asyncf
@@ -1547,6 +1563,7 @@ def __init__(self,
1547
1563
shell_prompt = DEFAULT_SHELL_PROMPT ,
1548
1564
conn_cls = SshConnection ,
1549
1565
is_container = False ,
1566
+ max_async = 50 ,
1550
1567
):
1551
1568
super (LinuxTarget , self ).__init__ (connection_settings = connection_settings ,
1552
1569
platform = platform ,
@@ -1557,7 +1574,8 @@ def __init__(self,
1557
1574
load_default_modules = load_default_modules ,
1558
1575
shell_prompt = shell_prompt ,
1559
1576
conn_cls = conn_cls ,
1560
- is_container = is_container )
1577
+ is_container = is_container ,
1578
+ max_async = max_async )
1561
1579
1562
1580
def wait_boot_complete (self , timeout = 10 ):
1563
1581
pass
@@ -1752,6 +1770,7 @@ def __init__(self,
1752
1770
conn_cls = AdbConnection ,
1753
1771
package_data_directory = "/data/data" ,
1754
1772
is_container = False ,
1773
+ max_async = 50 ,
1755
1774
):
1756
1775
super (AndroidTarget , self ).__init__ (connection_settings = connection_settings ,
1757
1776
platform = platform ,
@@ -1762,7 +1781,8 @@ def __init__(self,
1762
1781
load_default_modules = load_default_modules ,
1763
1782
shell_prompt = shell_prompt ,
1764
1783
conn_cls = conn_cls ,
1765
- is_container = is_container )
1784
+ is_container = is_container ,
1785
+ max_async = max_async )
1766
1786
self .package_data_directory = package_data_directory
1767
1787
self ._init_logcat_lock ()
1768
1788
@@ -2819,6 +2839,7 @@ def __init__(self,
2819
2839
shell_prompt = DEFAULT_SHELL_PROMPT ,
2820
2840
conn_cls = LocalConnection ,
2821
2841
is_container = False ,
2842
+ max_async = 50 ,
2822
2843
):
2823
2844
super (LocalLinuxTarget , self ).__init__ (connection_settings = connection_settings ,
2824
2845
platform = platform ,
@@ -2829,7 +2850,8 @@ def __init__(self,
2829
2850
load_default_modules = load_default_modules ,
2830
2851
shell_prompt = shell_prompt ,
2831
2852
conn_cls = conn_cls ,
2832
- is_container = is_container )
2853
+ is_container = is_container ,
2854
+ max_async = max_async )
2833
2855
2834
2856
def _resolve_paths (self ):
2835
2857
if self .working_directory is None :
@@ -2902,7 +2924,8 @@ def __init__(self,
2902
2924
load_default_modules = True ,
2903
2925
shell_prompt = DEFAULT_SHELL_PROMPT ,
2904
2926
package_data_directory = "/data/data" ,
2905
- is_container = False
2927
+ is_container = False ,
2928
+ max_async = 50 ,
2906
2929
):
2907
2930
2908
2931
self .supports_android = None
@@ -2928,7 +2951,8 @@ def __init__(self,
2928
2951
load_default_modules = load_default_modules ,
2929
2952
shell_prompt = shell_prompt ,
2930
2953
conn_cls = SshConnection ,
2931
- is_container = is_container )
2954
+ is_container = is_container ,
2955
+ max_async = max_async )
2932
2956
2933
2957
# We can't determine if the target supports android until connected to the linux host so
2934
2958
# create unconditionally.
0 commit comments