diff --git a/module/device/connection.py b/module/device/connection.py index 6610000d4..cbe709598 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -34,7 +34,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/adb.py b/module/device/method/adb.py index f699b7309..e6d2bde40 100644 --- a/module/device/method/adb.py +++ b/module/device/method/adb.py @@ -27,7 +27,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/ascreencap.py b/module/device/method/ascreencap.py index 24ba9902c..f793ff411 100644 --- a/module/device/method/ascreencap.py +++ b/module/device/method/ascreencap.py @@ -1,4 +1,5 @@ import os +import time from functools import wraps import lz4.block @@ -27,7 +28,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/droidcast.py b/module/device/method/droidcast.py index 43dad33cc..a8fe50d20 100644 --- a/module/device/method/droidcast.py +++ b/module/device/method/droidcast.py @@ -1,3 +1,4 @@ +import time import typing as t from functools import wraps @@ -30,7 +31,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/hermit.py b/module/device/method/hermit.py index 8b1da67ab..3fe6b05ba 100644 --- a/module/device/method/hermit.py +++ b/module/device/method/hermit.py @@ -1,4 +1,5 @@ import json +import time from functools import wraps import requests @@ -29,7 +30,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/ldopengl.py b/module/device/method/ldopengl.py index 4e4687173..bcaa5e3b4 100644 --- a/module/device/method/ldopengl.py +++ b/module/device/method/ldopengl.py @@ -145,7 +145,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/maatouch.py b/module/device/method/maatouch.py index cff9cedae..146cf7fa2 100644 --- a/module/device/method/maatouch.py +++ b/module/device/method/maatouch.py @@ -30,7 +30,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/minitouch.py b/module/device/method/minitouch.py index f23dcdf55..d97c2ca88 100644 --- a/module/device/method/minitouch.py +++ b/module/device/method/minitouch.py @@ -383,7 +383,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/nemu_ipc.py b/module/device/method/nemu_ipc.py index b1ab61a79..f2053c589 100644 --- a/module/device/method/nemu_ipc.py +++ b/module/device/method/nemu_ipc.py @@ -2,6 +2,7 @@ import ctypes import json import os import sys +import time from functools import wraps import cv2 @@ -163,9 +164,14 @@ def retry(func): """ init = None for _ in range(RETRY_TRIES): + # Extend timeout on retries + if func.__name__ == 'screenshot': + timeout = retry_sleep(_) + if timeout > 0: + kwargs['timeout'] = timeout try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle @@ -360,6 +366,10 @@ class NemuIpcImpl: @retry def screenshot(self, timeout=0.5): """ + Args: + timeout: Timout in seconds to call nemu_ipc + Will be dynamically extended by `@retry` + Returns: np.ndarray: Image array in RGBA color space Note that image is upside down @@ -562,8 +572,7 @@ class NemuIpc(Platform): logger.info('nemu_ipc released') def screenshot_nemu_ipc(self): - timeout = max(self._screenshot_interval.limit - 0.01, 0.15) - image = self.nemu_ipc.screenshot(timeout=timeout) + image = self.nemu_ipc.screenshot() image = cv2.cvtColor(image, cv2.COLOR_BGRA2BGR) cv2.flip(image, 0, dst=image) diff --git a/module/device/method/scrcpy/scrcpy.py b/module/device/method/scrcpy/scrcpy.py index d666a11ae..a4d5afb2a 100644 --- a/module/device/method/scrcpy/scrcpy.py +++ b/module/device/method/scrcpy/scrcpy.py @@ -26,7 +26,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/uiautomator_2.py b/module/device/method/uiautomator_2.py index d5d4e951d..5fa41801a 100644 --- a/module/device/method/uiautomator_2.py +++ b/module/device/method/uiautomator_2.py @@ -1,3 +1,4 @@ +import time import typing as t from dataclasses import dataclass from functools import wraps @@ -28,7 +29,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle diff --git a/module/device/method/utils.py b/module/device/method/utils.py index dc8e7ae3b..ad8d72bd4 100644 --- a/module/device/method/utils.py +++ b/module/device/method/utils.py @@ -154,16 +154,16 @@ class ImageTruncated(Exception): def retry_sleep(trial): # First trial if trial == 0: - pass + return 0 # Failed once, fast retry elif trial == 1: - pass + return 0 # Failed twice elif trial == 2: - time.sleep(1) + return 1 # Failed more else: - time.sleep(RETRY_DELAY) + return RETRY_DELAY def handle_adb_error(e): diff --git a/module/device/method/wsa.py b/module/device/method/wsa.py index 6ae1c6028..0a6018cec 100644 --- a/module/device/method/wsa.py +++ b/module/device/method/wsa.py @@ -1,4 +1,5 @@ import re +import time from functools import wraps from adbutils.errors import AdbError @@ -21,7 +22,7 @@ def retry(func): for _ in range(RETRY_TRIES): try: if callable(init): - retry_sleep(_) + time.sleep(retry_sleep(_)) init() return func(self, *args, **kwargs) # Can't handle