From ce65ea1fc199c2729b1a4fe3028975fedfc2da72 Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Fri, 13 Jun 2025 14:05:11 +0800 Subject: [PATCH] Fix: Change allocate_container_blocking Calculate Time by async time (#8206) ### What problem does this PR solve? Change allocate_container_blocking Calculate Time by async time ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Kevin Hu --- sandbox/executor_manager/core/container.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sandbox/executor_manager/core/container.py b/sandbox/executor_manager/core/container.py index 35e66d9cb..a026de112 100644 --- a/sandbox/executor_manager/core/container.py +++ b/sandbox/executor_manager/core/container.py @@ -16,7 +16,6 @@ import asyncio import contextlib import os -import time from queue import Empty, Queue from threading import Lock @@ -165,11 +164,10 @@ async def release_container(name: str, language: SupportLanguage): async def allocate_container_blocking(language: SupportLanguage, timeout=10) -> str: """Asynchronously allocate an available container""" - start_time = time.time() - while time.time() - start_time < timeout: + start_time = asyncio.get_running_loop().time() + while asyncio.get_running_loop().time() - start_time < timeout: try: name = _CONTAINER_QUEUES[language].get_nowait() - with _CONTAINER_LOCK: if not await container_is_running(name) and not await recreate_container(name, language): continue