mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-17 20:25:27 +08:00
Opt: Faster remove_shell_warning() and lower CPU usage in *_nc screenshot methods
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
import time
|
||||||
|
|
||||||
import uiautomator2 as u2
|
import uiautomator2 as u2
|
||||||
from adbutils import AdbTimeout, _AdbStreamConnection
|
from adbutils import AdbTimeout, _AdbStreamConnection
|
||||||
@@ -59,6 +60,8 @@ def recv_all(stream, chunk_size=4096) -> bytes:
|
|||||||
chunk = stream.recv(chunk_size)
|
chunk = stream.recv(chunk_size)
|
||||||
if chunk:
|
if chunk:
|
||||||
fragments.append(chunk)
|
fragments.append(chunk)
|
||||||
|
# See https://stackoverflow.com/questions/23837827/python-server-program-has-high-cpu-usage/41749820#41749820
|
||||||
|
time.sleep(0.001)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
return remove_shell_warning(b''.join(fragments))
|
return remove_shell_warning(b''.join(fragments))
|
||||||
@@ -196,10 +199,21 @@ def remove_shell_warning(s):
|
|||||||
Returns:
|
Returns:
|
||||||
str, bytes:
|
str, bytes:
|
||||||
"""
|
"""
|
||||||
|
# WARNING: linker: [vdso]: unused DT entry: type 0x70000001 arg 0x0\n\x89PNG\r\n\x1a\n\x00\x00\x00\rIH
|
||||||
if isinstance(s, bytes):
|
if isinstance(s, bytes):
|
||||||
return re.sub(b'^WARNING.+\n', b'', s)
|
if s.startswith(b'WARNING'):
|
||||||
|
try:
|
||||||
|
s = s.split(b'\n', maxsplit=1)[1]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
return s
|
||||||
|
# return re.sub(b'^WARNING.+\n', b'', s)
|
||||||
elif isinstance(s, str):
|
elif isinstance(s, str):
|
||||||
return re.sub('^WARNING.+\n', '', s)
|
if s.startswith('WARNING'):
|
||||||
|
try:
|
||||||
|
s = s.split('\n', maxsplit=1)[1]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user