mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-24 04:25:56 +08:00
Fix: Cleanup after subprocess.Popen.communicate()
This commit is contained in:
@@ -184,10 +184,15 @@ class EmulatorConnect:
|
|||||||
def __init__(self, adb='adb.exe'):
|
def __init__(self, adb='adb.exe'):
|
||||||
self.adb_binary = adb
|
self.adb_binary = adb
|
||||||
|
|
||||||
def _execute(self, cmd):
|
def _execute(self, cmd, timeout=10):
|
||||||
print(' '.join(cmd))
|
print(' '.join(cmd))
|
||||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
|
||||||
stdout, stderr = process.communicate(timeout=10)
|
try:
|
||||||
|
stdout, stderr = process.communicate(timeout=timeout)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
process.kill()
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
print(f'TimeoutExpired, stdout={stdout}, stderr={stderr}')
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|||||||
@@ -245,7 +245,13 @@ class Connection:
|
|||||||
|
|
||||||
# No gooey anymore, just shell=False
|
# No gooey anymore, just shell=False
|
||||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False)
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False)
|
||||||
return process.communicate(timeout=timeout)[0]
|
try:
|
||||||
|
stdout, stderr = process.communicate(timeout=timeout)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
process.kill()
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
logger.warning(f'TimeoutExpired when calling {cmd}, stdout={stdout}, stderr={stderr}')
|
||||||
|
return stdout
|
||||||
|
|
||||||
def adb_shell(self, cmd, **kwargs):
|
def adb_shell(self, cmd, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user