From 96e5b9ea140fce23eef896e9fe6bd478309eee94 Mon Sep 17 00:00:00 2001 From: chendelian <116870791@qq.com> Date: Tue, 7 Apr 2026 10:58:32 +0800 Subject: [PATCH] fix: spawn login/open child with python -m for PyArmor runtime path --- scripts/service/browser_service.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/service/browser_service.py b/scripts/service/browser_service.py index ec18769..684de89 100644 --- a/scripts/service/browser_service.py +++ b/scripts/service/browser_service.py @@ -21,6 +21,9 @@ from util.platforms import ( # 子进程入口脚本与本模块同目录(独立解释器执行,非 import) _SERVICE_DIR = os.path.dirname(os.path.abspath(__file__)) +# PyArmor 在模块首行注入对 pyarmor_runtime_* 的 import;若以「脚本路径」启动子进程, +# sys.path[0] 仅为 service/,找不到 scripts/ 下的运行时包。必须用 -m 且 cwd=scripts/(标准做法)。 +_SCRIPTS_ROOT = os.path.dirname(_SERVICE_DIR) def _win_find_exe(candidates): @@ -196,7 +199,6 @@ def _run_login_browser_session( url, log_file, ) - login_runner_path = os.path.join(_SERVICE_DIR, "login_child_runner.py") cfg = { "channel": channel, "profile_dir": profile_dir, @@ -223,7 +225,8 @@ def _run_login_browser_session( child_stdout = "" try: r = subprocess.run( - [sys.executable, login_runner_path, cfg_path], + [sys.executable, "-m", "service.login_child_runner", cfg_path], + cwd=_SCRIPTS_ROOT, timeout=timeout_sec + 180, env=subprocess_env_with_trace(), capture_output=True, @@ -481,7 +484,6 @@ def cmd_open(account_id): print("请在本窗口中自行确认登录态。关闭浏览器后命令结束。") print("需要自动检测登录时,请执行:python main.py login ") - open_runner_path = os.path.join(_SERVICE_DIR, "open_child_runner.py") cfg = {"channel": channel, "profile_dir": profile_dir, "url": url} with tempfile.NamedTemporaryFile( mode="w", suffix=".json", delete=False, encoding="utf-8" @@ -490,7 +492,8 @@ def cmd_open(account_id): cfg_path = jf.name try: subprocess.run( - [sys.executable, open_runner_path, cfg_path], + [sys.executable, "-m", "service.open_child_runner", cfg_path], + cwd=_SCRIPTS_ROOT, env=subprocess_env_with_trace(), ) finally: