File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,16 @@ async def exit_handler(signame=None):
7070 logger .info ("Good bye!" )
7171
7272
73+ async def run_with_signals ():
74+ loop = asyncio .get_running_loop ()
75+ for signame in ("SIGINT" , "SIGTERM" ):
76+ sig = getattr (signal , signame )
77+ loop .add_signal_handler (
78+ sig , lambda s = signame : asyncio .ensure_future (exit_handler (s ))
79+ )
80+ await run_loop ()
81+
82+
7383async def run_loop ():
7484 retry = 1
7585 while alarm is not None :
@@ -131,17 +141,10 @@ def main(args):
131141
132142 # Start interacting with the alarm
133143 alarm = Paradox ()
134- loop = asyncio .get_event_loop ()
135- for signame in ("SIGINT" , "SIGTERM" ):
136- sig = getattr (signal , signame )
137- loop .add_signal_handler (
138- sig , lambda s = signame : asyncio .ensure_future (exit_handler (s ))
139- )
140144
141145 interface_manager = InterfaceManager (alarm , config = cfg )
142146 interface_manager .start ()
143147
144- loop = asyncio .get_event_loop ()
145- loop .run_until_complete (run_loop ())
148+ asyncio .run (run_with_signals ())
146149
147150 sys .exit (0 )
You can’t perform that action at this time.
0 commit comments