File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import asyncio
4
4
import signal
5
+ from concurrent .futures import FIRST_EXCEPTION
5
6
from typing import TYPE_CHECKING
6
7
7
8
import uvloop
@@ -53,11 +54,23 @@ async def override_signal_handler() -> None:
53
54
54
55
tasks .append (loop .create_task (override_signal_handler ()))
55
56
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
61
74
62
75
63
76
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments