Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions android_env/components/adb_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ def execute_command(
command = self.command_prefix(include_device_name=device_specific) + args
command_str = 'adb ' + ' '.join(command[1:])

n_retries = 2
n_tries = 1
n_tries = 2
latest_error = None
while n_tries <= n_retries:
for i in range(n_tries):
try:
logging.info('Executing ADB command: [%s]', command_str)
cmd_output = subprocess.check_output(
Expand All @@ -140,7 +139,8 @@ def execute_command(
return cmd_output
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
logging.exception(
'Failed to execute ADB command (try %r of 3): [%s]',
'Failed to execute ADB command (try %d of %d): [%s]',
i + 1,
n_tries,
command_str,
)
Expand All @@ -152,14 +152,11 @@ def execute_command(
logging.error('**stderr**:')
for line in e.stderr.splitlines():
logging.error(' %s', line)
n_tries += 1
latest_error = e
if device_specific and n_tries <= n_retries:
if device_specific and i < n_tries - 1:
self._restart_server(timeout=timeout)

raise errors.AdbControllerError(
f'Error executing adb command: [{command_str}]\n'
f'Caused by: {latest_error}\n'
f'adb stdout: [{latest_error.stdout}]\n'
f'adb stderr: [{latest_error.stderr}]'
f'Caused by: {latest_error}'
) from latest_error