From ac8b194ca83a62e1260350d8004a888e9ea7958c Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Mon, 19 Oct 2026 13:46:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=97=B6=E9=99=90=E4=B8=8D?= =?UTF-8?q?=E7=AE=97=E6=8E=92=E9=98=9F=EF=BC=88=E7=BB=AD=EF=BC=89=EF=BC=9A?= =?UTF-8?q?within=20=E7=9C=8B=E5=BE=97=E6=9B=B4=E5=8B=A4=EF=BC=88=E4=B8=8D?= =?UTF-8?q?=E8=B6=85=E8=BF=87=E6=97=B6=E9=99=90=E7=9A=84=201/20=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E4=B8=80=E6=AE=B5=E7=9A=84=E5=A4=B4=E5=B0=BE=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E5=A4=B4=E5=9C=A8=E6=9A=82=E5=81=9C=E5=B0=B1=E6=95=B4?= =?UTF-8?q?=E6=AE=B5=E4=B8=8D=E7=AE=97=E2=80=94=E2=80=94=E4=BB=A5=E5=89=8D?= =?UTF-8?q?=E4=B8=80=E6=AE=B5=E5=8F=AA=E7=9C=8B=E5=B0=BE=E5=B7=B4=EF=BC=8C?= =?UTF-8?q?=E6=8B=BF=E5=88=B0=E5=90=8D=E9=A2=9D=E5=90=8E=E7=9A=84=E5=A4=B4?= =?UTF-8?q?=E4=B8=80=E6=AE=B5=E6=95=B4=E6=AE=B5=E7=AE=97=E8=BF=9B=E5=8E=BB?= =?UTF-8?q?=EF=BC=8CPostgreSQL=20=E5=85=A8=E9=87=8F=E6=BB=A1=E8=BD=BD?= =?UTF-8?q?=E6=97=B6=E9=82=A3=E6=9D=A1=E6=B5=8B=E8=AF=95=E5=81=B6=E5=8F=91?= =?UTF-8?q?=E8=B6=85=E6=97=B6=EF=BC=9B=E6=B5=8B=E8=AF=95=E6=94=B9=E6=88=90?= =?UTF-8?q?=E6=8E=92=202=20=E7=A7=92=E3=80=81=E6=97=B6=E9=99=90=201=20?= =?UTF-8?q?=E7=A7=92=EF=BC=8C=E7=BB=99=E6=8B=BF=E5=88=B0=E5=90=8D=E9=A2=9D?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E7=9A=84=E5=87=A0=E6=AC=A1=E5=86=99=E5=BA=93?= =?UTF-8?q?=E7=95=99=E5=A4=9F=E4=BD=99=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/eval/runner.py | 11 ++++++++--- backend/tests/test_eval_runner.py | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/app/eval/runner.py b/backend/app/eval/runner.py index af8718f7..a552a528 100644 --- a/backend/app/eval/runner.py +++ b/backend/app/eval/runner.py @@ -976,19 +976,24 @@ async def _queued(driver: Any) -> bool: async def within(coro: Any, budget: float, paused: Any, *, tick: float = 0.5) -> Any: """同 asyncio.wait_for(coro, budget),只是 paused() 为真的那几段不算时间(复核:满载时排队等名额不该算进每题时限、触发止损)。 - 超时取消 coro、抛 TimeoutError。""" + 超时取消 coro、抛 TimeoutError。每隔一小段(tick,且不超过时限的 1/20)看一次;一段的头尾有一头在暂停就整段不算—— + 宁可少算一点,不把排队的时间算进去。""" loop = asyncio.get_running_loop() task = asyncio.ensure_future(coro) + step_s = max(0.005, min(tick, budget / 20)) spent, last = 0.0, loop.time() + was_paused = await paused() try: while True: - done, _ = await asyncio.wait({task}, timeout=max(0.02, min(tick, budget - spent))) + done, _ = await asyncio.wait({task}, timeout=max(0.005, min(step_s, budget - spent))) if task in done: return task.result() now = loop.time() step, last = now - last, now - if not await paused(): + is_paused = await paused() + if not (was_paused or is_paused): spent += step + was_paused = is_paused if spent >= budget: task.cancel() with contextlib.suppress(asyncio.CancelledError, Exception): diff --git a/backend/tests/test_eval_runner.py b/backend/tests/test_eval_runner.py index 94a9c106..6aaaa484 100644 --- a/backend/tests/test_eval_runner.py +++ b/backend/tests/test_eval_runner.py @@ -290,7 +290,7 @@ async def test_a_case_over_its_time_limit_stops_its_run(monkeypatch): async def test_time_queued_for_a_run_slot_does_not_count_against_the_case_limit(monkeypatch): - """复核:满载时作答运行排队等名额的那一段不算每题时限(排了 0.8 秒、时限 0.3 秒,拿到名额后很快答完:不记超时)。""" + """复核:满载时作答运行排队等名额的那一段不算每题时限(排了 2 秒、时限 1 秒,拿到名额后很快答完:不记超时)。""" from app.cluster import slots stored = slots.values({"max_total": 2, "interactive_reserve": 1}) @@ -321,7 +321,7 @@ async def test_time_queued_for_a_run_slot_does_not_count_against_the_case_limit( async def prepare(self): units = await original(self) - self.budget["per_case_timeout_s"] = 0.3 + self.budget["per_case_timeout_s"] = 1.0 return units monkeypatch.setattr(runner.EvalExecution, "_prepare", prepare) @@ -333,7 +333,7 @@ async def test_time_queued_for_a_run_slot_does_not_count_against_the_case_limit( [run] = await start(suite_id) while not await slots.waiting("eval-answer-in-queue"): await asyncio.sleep(0.02) - await asyncio.sleep(0.8) + await asyncio.sleep(2.0) gate.set() await es.wait_eval(run.id) finally: