From d8a545dd4a1d99af581c307ae999c8f14c2884eb Mon Sep 17 00:00:00 2001 From: GenericAgent Date: Fri, 13 Nov 2026 00:30:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(code=5Frun):=20=E7=94=A8=20reader=20join=20?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=E5=9B=BA=E5=AE=9A=20sleep(1)=20=E8=BD=AE?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 进程结束后最长仍要空等 1s 才发现。改为 t.join(0.05) 后一退出即返回。 本机 5.2k 次响应间隔统计中位恰为 1.000s(2012 次精确 1s, code_run 占 1912), 实测短任务 1.01s->0.24s, 3000 行输出 1.01s->0.37s, 退出码与超时行为不变。 补 process.wait() 兜底: reader 可能先于进程回收退出导致 poll() 为 None。 --- ga.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ga.py b/ga.py index 82c508994..23bc3290d 100644 --- a/ga.py +++ b/ga.py @@ -73,10 +73,13 @@ def stream_reader(proc, logs): if istimeout: full_stdout.append("\n[Timeout Error] 超时强制终止") else: full_stdout.append("\n[Stopped] 用户强制终止") break - time.sleep(1) + t.join(0.05) # 等 reader 退出, 不再固定 sleep(1) t.join(timeout=1) exit_code = process.poll() + if exit_code is None: # reader 可能先于进程回收退出 + try: exit_code = process.wait(timeout=5) + except subprocess.TimeoutExpired: exit_code = process.poll() stdout_str = "".join(full_stdout) status = "success" if exit_code == 0 else "error"