mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-07 07:47:07 +08:00
Opt: [ALAS] Dynamically extends nemu_ipc timeout on retries for slow PCs
This commit is contained in:
parent
a6f81729e5
commit
3d112b4c6c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user