File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python3
2
2
import asyncio
3
3
import sys
4
+ from signal import SIGINT , SIGTERM
4
5
5
6
from gql .cli import get_parser , main
6
7
@@ -9,8 +10,23 @@ parser = get_parser(with_examples=True)
9
10
args = parser .parse_args ()
10
11
11
12
try :
12
- # Execute the script
13
- exit_code = asyncio .run (main (args ))
13
+ # Create a new asyncio event loop
14
+ loop = asyncio .new_event_loop ()
15
+ asyncio .set_event_loop (loop )
16
+
17
+ # Create a gql-cli task with the supplied arguments
18
+ main_task = asyncio .ensure_future (main (args ), loop = loop )
19
+
20
+ # Add signal handlers to close gql-cli cleanly on Control-C
21
+ for signal in [SIGINT , SIGTERM ]:
22
+ loop .add_signal_handler (signal , main_task .cancel )
23
+
24
+ # Run the asyncio loop to execute the task
25
+ exit_code = 0
26
+ try :
27
+ exit_code = loop .run_until_complete (main_task )
28
+ finally :
29
+ loop .close ()
14
30
15
31
# Return with the correct exit code
16
32
sys .exit (exit_code )
You can’t perform that action at this time.
0 commit comments