pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/msgpack-rpc/msgpack-rpc-python/pull/2/files

ithub.githubassets.com/assets/primer-primitives-10bf9dd67e3d70bd.css" /> Graceful shutdown support by Leechael · Pull Request #2 · msgpack-rpc/msgpack-rpc-python · GitHub
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions msgpackrpc/loop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from tornado import ioloop
import signal
from time import time

class Loop(object):
"""\
Expand All @@ -19,6 +21,10 @@ def start(self):
Starts the Tornado's ioloop if it's not running.
"""

handler = _LoopShutdownHandler(self._ioloop)
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGHUP, handler)
self._ioloop.start()

def stop(self):
Expand All @@ -42,3 +48,20 @@ def dettach_periodic_callback(self):
if self._periodic_callback is not None:
self._periodic_callback.stop()
self._periodic_callback = None


class _LoopShutdownHandler:
def __init__(self, loop):
self._ioloop = loop

def __call__(self, *args, **argv):
loop = self._ioloop
deadline = time() + 3

def stop():
now = time()
if now < deadline and (loop._callbacks or loop._timeouts):
loop.add_timeout(now + 1, stop)
else:
loop.stop()
stop()
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy