Skip to content

Commit 7ef16bf

Browse files
committed
In Docker container crash fix
1 parent 36225e1 commit 7ef16bf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

paradox/main.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff 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+
7383
async 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)

0 commit comments

Comments
 (0)