Skip to content

Commit 0153238

Browse files
committed
__main__: improve error handling in start_servers()
1 parent 9646c14 commit 0153238

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/vllm_tgis_adapter/__main__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import signal
5+
from concurrent.futures import FIRST_EXCEPTION
56
from typing import TYPE_CHECKING
67

78
import uvloop
@@ -53,11 +54,23 @@ async def override_signal_handler() -> None:
5354

5455
tasks.append(loop.create_task(override_signal_handler()))
5556

56-
try:
57-
await asyncio.wait(tasks)
58-
except asyncio.CancelledError:
59-
for task in tasks:
60-
task.cancel()
57+
done, pending = await asyncio.wait(
58+
tasks,
59+
return_when=FIRST_EXCEPTION,
60+
)
61+
for task in pending:
62+
task.cancel()
63+
64+
while done:
65+
task = done.pop()
66+
exc = task.exception()
67+
if not exc:
68+
continue
69+
70+
name = task.get_name()
71+
coro_name = task.get_coro().__name__
72+
73+
raise RuntimeError(f"task={name} ({coro_name})") from exc
6174

6275

6376
if __name__ == "__main__":

0 commit comments

Comments
 (0)