Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化对本地模拟器的连接速度 #852

Merged
merged 1 commit into from
Mar 20, 2024
Merged

Conversation

LmeSzinc
Copy link
Contributor

@LmeSzinc LmeSzinc commented Dec 4, 2022

本地模拟器使用 127.0.0.1:5555, emulator-5554 等作为 serial。调用 u2.connect() 时,_fix_wifi_addr() 会请求 http://emulator-5554/version,但需要等待 requests 超时才会抛出域名解析错误的异常,请求 http://127.0.0.1:5555/version 也需要等到读取超时

emulator- 开头或者是 127.0.0.1: 开头的都是本地模拟器了,直接绕过可以节省两秒钟

def _fix_wifi_addr(addr: str) -> Optional[str]:
if not addr:
return None
if re.match(r"^https?://", addr): # eg: http://example.org
return addr
# make a request
# eg: 10.0.0.1, 10.0.0.1:7912
if ':' not in addr:
addr += ":7912" # make default port 7912
try:
r = requests.get("http://" + addr + "/version", timeout=2)
r.raise_for_status()
return "http://" + addr
except:
return None

@LmeSzinc LmeSzinc changed the title 优化对emulator-5554的连接速度 优化对本地模拟器的连接速度 Dec 4, 2022
@luochan1028
Copy link

t

@codeskyblue codeskyblue merged commit 522f823 into openatx:master Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants