Merge pull request #1770 from dst03106/fix/add-ttl-when-callback-enabled

fix: add timeout to asyncio.wait during CLI execution to avoid hanging when callback is enabled
This commit is contained in:
Tal
2025-05-13 18:33:56 +03:00
committed by GitHub

View File

@ -86,7 +86,13 @@ def run(inargs=None, args=None):
if get_settings().litellm.get("enable_callbacks", False):
# There may be additional events on the event queue from the run above. If there are give them time to complete.
get_logger().debug("Waiting for event queue to complete")
await asyncio.wait([task for task in asyncio.all_tasks() if task is not asyncio.current_task()])
tasks = [task for task in asyncio.all_tasks() if task is not asyncio.current_task()]
if tasks:
_, pending = await asyncio.wait(tasks, timeout=30)
if pending:
get_logger().warning(
f"{len(pending)} callback tasks({[task.get_coro() for task in pending]}) did not complete within timeout"
)
return result