def retry_wrapper(self, *args, **kwargs): """ Args: self (Hermit): """ init = None for _ in range(RETRY_TRIES): try: if callable(init): self.sleep(RETRY_DELAY) init() return func(self, *args, **kwargs) # Can't handle except RequestHumanTakeover: break # When adb server was killed except ConnectionResetError as e: logger.error(e) def init(): self.adb_reconnect() # When unable to send requests except requests.exceptions.ConnectionError as e: logger.error(e) text = str(e) if 'Connection aborted' in text: # Hermit not installed or not running # ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) def init(): self.adb_reconnect() self.hermit_init() else: # Lost connection, adb server was killed # HTTPConnectionPool(host='127.0.0.1', port=20269): # Max retries exceeded with url: /click?x=500&y=500 def init(): self.adb_reconnect() # AdbError except AdbError as e: if handle_adb_error(e): def init(): self.adb_reconnect() else: break # HermitError: {"code":-1,"msg":"error"} except HermitError as e: logger.error(e) def init(): self.adb_reconnect() self.hermit_init() # Unknown, probably a trucked image except Exception as e: logger.exception(e) def init(): pass logger.critical(f'Retry {func.__name__}() failed') raise RequestHumanTakeover
def retry_wrapper(self, *args, **kwargs): """ Args: self (AScreenCap): """ init = None for _ in range(RETRY_TRIES): try: if callable(init): self.sleep(RETRY_DELAY) init() return func(self, *args, **kwargs) # Can't handle except RequestHumanTakeover: break # When adb server was killed except ConnectionResetError as e: logger.error(e) def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) # When ascreencap is not installed except AscreencapError as e: logger.error(e) def init(): self.ascreencap_init() # AdbError except AdbError as e: if handle_adb_error(e): def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) else: break # Unknown, probably a trucked image except Exception as e: logger.exception(e) def init(): pass logger.critical(f'Retry {func.__name__}() failed') raise RequestHumanTakeover
def retry_wrapper(self, *args, **kwargs): """ Args: self (Uiautomator2): """ init = None sleep = True for _ in range(RETRY_TRIES): try: if callable(init): if sleep: self.sleep(RETRY_DELAY) sleep = True init() return func(self, *args, **kwargs) # Can't handle except RequestHumanTakeover: break # When adb server was killed except ConnectionResetError as e: logger.error(e) def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) # In `device.set_new_command_timeout(604800)` # json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1) except JSONDecodeError as e: logger.error(e) sleep = False def init(): self.install_uiautomator2() # AdbError except AdbError as e: if handle_adb_error(e): def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) else: break # RuntimeError: USB device 127.0.0.1:5555 is offline except RuntimeError as e: if handle_adb_error(e): def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) else: break # In `assert c.read string(4) == _OKAY` # ADB on emulator not enabled except AssertionError as e: logger.exception(e) possible_reasons( 'If you are using BlueStacks or LD player, ' 'please enable ADB in the settings of your emulator') break # Unknown, probably a trucked image except Exception as e: logger.exception(e) def init(): pass logger.critical(f'Retry {func.__name__}() failed') raise RequestHumanTakeover
def retry_wrapper(self, *args, **kwargs): """ Args: self (Minitouch): """ init = None sleep = True for _ in range(RETRY_TRIES): try: if callable(init): if sleep: self.sleep(RETRY_DELAY) sleep = True init() return func(self, *args, **kwargs) # Can't handle except RequestHumanTakeover: break # When adb server was killed except ConnectionResetError as e: logger.error(e) def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) # Emulator closed except ConnectionAbortedError as e: logger.error(e) def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) # MinitouchNotInstalledError: Received empty data from minitouch except MinitouchNotInstalledError as e: logger.error(e) sleep = False def init(): self.install_uiautomator2() if self._minitouch_port: self.adb_forward_remove(f'tcp:{self._minitouch_port}') del_cached_property(self, 'minitouch_builder') # MinitouchOccupiedError: Timeout when connecting to minitouch except MinitouchOccupiedError as e: logger.error(e) sleep = False def init(): self.restart_atx() if self._minitouch_port: self.adb_forward_remove(f'tcp:{self._minitouch_port}') del_cached_property(self, 'minitouch_builder') # AdbError except AdbError as e: if handle_adb_error(e): def init(): self.adb_disconnect(self.serial) self.adb_connect(self.serial) else: break except BrokenPipeError as e: logger.error(e) def init(): del_cached_property(self, 'minitouch_builder') # Unknown, probably a trucked image except Exception as e: logger.exception(e) def init(): pass logger.critical(f'Retry {func.__name__}() failed') raise RequestHumanTakeover