Merge pull request #1978 from lbryio/sigint

handle sigint
This commit is contained in:
Jack Robison 2019-03-12 15:06:08 -04:00 committed by GitHub
commit 0cc602ca53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
import os
import sys
import signal
import pathlib
import json
import asyncio
@ -272,8 +273,20 @@ def main(argv=None):
log.addHandler(loggly_handler)
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:
loop.run_until_complete(daemon.start())
started = True
loop.run_until_complete(daemon.stop_event.wait())
except (GracefulExit, KeyboardInterrupt):
pass