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 <kevinhu.sh@gmail.com>
This commit is contained in:
Stephen Hu
2025-06-13 14:05:11 +08:00
committed by GitHub
parent 2341939376
commit ce65ea1fc1

View File

@ -16,7 +16,6 @@
import asyncio import asyncio
import contextlib import contextlib
import os import os
import time
from queue import Empty, Queue from queue import Empty, Queue
from threading import Lock 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: async def allocate_container_blocking(language: SupportLanguage, timeout=10) -> str:
"""Asynchronously allocate an available container""" """Asynchronously allocate an available container"""
start_time = time.time() start_time = asyncio.get_running_loop().time()
while time.time() - start_time < timeout: while asyncio.get_running_loop().time() - start_time < timeout:
try: try:
name = _CONTAINER_QUEUES[language].get_nowait() name = _CONTAINER_QUEUES[language].get_nowait()
with _CONTAINER_LOCK: with _CONTAINER_LOCK:
if not await container_is_running(name) and not await recreate_container(name, language): if not await container_is_running(name) and not await recreate_container(name, language):
continue continue