Created
June 14, 2017 15:48
-
-
Save TomBaxter/165688c15d9c8c82d3df62df9a48e088 to your computer and use it in GitHub Desktop.
This file contains 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
def sig_handler(sig, frame): | |
io_loop = tornado.ioloop.IOLoop.instance() | |
def stop_loop(): | |
if len(asyncio.Task.all_tasks(io_loop)) == 0: | |
io_loop.stop() | |
else: | |
io_loop.call_later(1, stop_loop) | |
io_loop.add_callback_from_signal(stop_loop) | |
serv(): | |
tornado.platform.asyncio.AsyncIOMainLoop().install() | |
.... | |
signal.signal(signal.SIGTERM, partial(sig_handler)) | |
asyncio.get_event_loop().run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @wonderbeyond for the more complete example at https://gist.github.com/wonderbeyond/d38cd85243befe863cdde54b84505784