Created
June 30, 2016 13:51
-
-
Save athoune/26ba27446bbcab9f2b9d801723c67eda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import functools | |
import os | |
import signal | |
def ask_signal(signame, exit=False): | |
print("got signal %s" % signame) | |
if exit: | |
loop.stop() | |
loop = asyncio.get_event_loop() | |
for signame in ('SIGINT', 'SIGTERM'): | |
loop.add_signal_handler(getattr(signal, signame), | |
functools.partial(ask_signal, signame, True)) | |
for signame in ('SIGHUP', 'SIGUSR1'): | |
loop.add_signal_handler(getattr(signal, signame), | |
functools.partial(ask_signal, signame)) | |
print("Event loop running forever, press Ctrl+C to interrupt.") | |
print("pid %s: send SIGINT or SIGTERM to exit." % os.getpid()) | |
try: | |
loop.run_forever() | |
finally: | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment