From d1b863da4dda63c009ac82e52b7b3099b71cbf8d Mon Sep 17 00:00:00 2001 From: Aliothmoon Date: Sun, 22 Feb 2026 00:39:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E5=A4=8D=E7=94=A8=20AsyncClient=20?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=20ThreadPoolExecutor=20=E9=81=BF=E5=85=8D=20?= =?UTF-8?q?SSL=20=E4=B8=8A=E4=B8=8B=E6=96=87=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaDebugger/utils/update_checker/check.py | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/MaaDebugger/utils/update_checker/check.py b/src/MaaDebugger/utils/update_checker/check.py index 22c92c5..859a640 100644 --- a/src/MaaDebugger/utils/update_checker/check.py +++ b/src/MaaDebugger/utils/update_checker/check.py @@ -1,5 +1,4 @@ import asyncio -from concurrent.futures import ThreadPoolExecutor from enum import auto, Enum from typing import Any, Optional, Union @@ -11,7 +10,7 @@ PYPI_API = "https://pypi.org/pypi/MaaDebugger/json" TSINGHUA_PYPI_API = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/json/maadebugger" -_executor = ThreadPoolExecutor(max_workers=2) +_client = httpx.AsyncClient() class CheckStatus(Enum): @@ -19,15 +18,13 @@ class CheckStatus(Enum): SKIPPED = auto() -def _sync_get_from_pypi(url: str) -> Optional[str]: # -> '1.8.0b1' - """Synchronous version of get_from_pypi, runs in a thread pool.""" +async def _get_from_pypi(url: str) -> Optional[str]: # -> '1.8.0b1' try: - with httpx.Client() as client: - req = client.get(url, timeout=5) - if req.status_code == 200: - return req.json().get("info", {}).get("version", None) - else: - return None + req = await _client.get(url, timeout=5) + if req.status_code == 200: + return req.json().get("info", {}).get("version", None) + else: + return None except Exception as e: print(f"WARNING: Failed to check update from {url}", e) return None @@ -58,14 +55,12 @@ async def check_update() -> Union[CheckStatus, str, None]: return CheckStatus.FAILED else: - loop = asyncio.get_event_loop() - pypi = loop.run_in_executor(_executor, _sync_get_from_pypi, PYPI_API) - tsinghua_pypi = loop.run_in_executor( - _executor, _sync_get_from_pypi, TSINGHUA_PYPI_API + vers = await asyncio.gather( + _get_from_pypi(PYPI_API), + _get_from_pypi(TSINGHUA_PYPI_API), + return_exceptions=True, ) - vers = await asyncio.gather(pypi, tsinghua_pypi, return_exceptions=True) - check_number = len(vers) check_succeed_number = 0 From 3c52b823a68be42ce4c85be4084fb1e7e0d3570c Mon Sep 17 00:00:00 2001 From: weinibuliu Date: Sun, 22 Feb 2026 01:21:09 +0800 Subject: [PATCH 2/2] docs --- src/MaaDebugger/utils/update_checker/check.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MaaDebugger/utils/update_checker/check.py b/src/MaaDebugger/utils/update_checker/check.py index 859a640..690ef88 100644 --- a/src/MaaDebugger/utils/update_checker/check.py +++ b/src/MaaDebugger/utils/update_checker/check.py @@ -53,7 +53,6 @@ async def check_update() -> Union[CheckStatus, str, None]: return CheckStatus.SKIPPED elif "FAILED" in (__version__.tag_name, __version__.version): return CheckStatus.FAILED - else: vers = await asyncio.gather( _get_from_pypi(PYPI_API),