handle sigint
This commit is contained in:
parent
b266cde511
commit
f390ff144d
1 changed files with 13 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import signal
|
||||||
import pathlib
|
import pathlib
|
||||||
import json
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -272,8 +273,20 @@ def main(argv=None):
|
||||||
log.addHandler(loggly_handler)
|
log.addHandler(loggly_handler)
|
||||||
|
|
||||||
daemon = Daemon(conf)
|
daemon = Daemon(conf)
|
||||||
|
started = False
|
||||||
|
def __exit():
|
||||||
|
if started:
|
||||||
|
daemon.stop_event.set()
|
||||||
|
else:
|
||||||
|
raise GracefulExit()
|
||||||
|
try:
|
||||||
|
loop.add_signal_handler(signal.SIGINT, __exit)
|
||||||
|
loop.add_signal_handler(signal.SIGTERM, __exit)
|
||||||
|
except NotImplementedError:
|
||||||
|
pass # Not implemented on Windows
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(daemon.start())
|
loop.run_until_complete(daemon.start())
|
||||||
|
started = True
|
||||||
loop.run_until_complete(daemon.stop_event.wait())
|
loop.run_until_complete(daemon.stop_event.wait())
|
||||||
except (GracefulExit, KeyboardInterrupt):
|
except (GracefulExit, KeyboardInterrupt):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue