Python gevent.signal_handler() Examples
The following are 3
code examples of gevent.signal_handler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gevent
, or try the search function
.
Example #1
Source File: processes.py From mrq with MIT License | 6 votes |
def install_signal_handlers(self): """ Handle events like Ctrl-C from the command line. """ self.graceful_stop = False def request_shutdown_now(): self.shutdown_now() def request_shutdown_graceful(): # Second time CTRL-C, shutdown now if self.graceful_stop: self.shutdown_now() else: self.graceful_stop = True self.shutdown_graceful() # First time CTRL-C, try to shutdown gracefully gevent.signal_handler(signal.SIGINT, request_shutdown_graceful) # User (or Heroku) requests a stop now, just mark tasks as interrupted. gevent.signal_handler(signal.SIGTERM, request_shutdown_now)
Example #2
Source File: test_gipc.py From gipc with MIT License | 5 votes |
def test_orphaned_signal_watcher(self): # Install libev-based signal watcher. try: s = gevent.signal(signal.SIGTERM, signals_test_sigterm_handler) except AttributeError: # This function got renamed in gevent 1.5 s = gevent.signal_handler(signal.SIGTERM, signals_test_sigterm_handler) # Normal behavior: signal handlers become inherited by children. # Bogus behavior of libev-based signal watchers in child process: # They should not be active anymore when 'orphaned' (when their # corresponding event loop has been destroyed). What happens, however: # The old handler stays active and registering a new handler does not # 'overwrite' the old one -- both are active. # Since this test is about testing the behavior of 'orphaned' libev # signal watchers, the signal must be transmitted *after* event loop # recreation, so wait here for the child process to go through # the hub & event loop destruction (and recreation) process before # sending the signal. Waiting is realized with sync through pipe. # Without cleanup code in gipc, the inherited but orphaned libev signal # watcher would be active in the fresh event loop and trigger the # handler. This is a problem. With cleanup code, this handler must # never be called. Child exitcode 20 means that the inherited handler # has been called, -15 (-signal.SIGTERM) means that the child was # actually killed by SIGTERM within a certain short time interval. # Returncode 0 would mean that the child finished normally after that # short time interval. with pipe() as (r, w): p = start_process(signals_test_child_a, (w,)) assert r.get() == p.pid os.kill(p.pid, signal.SIGTERM) p.join() if not WINDOWS: assert p.exitcode == -signal.SIGTERM else: assert p.exitcode == signal.SIGTERM s.cancel()
Example #3
Source File: loadtest.py From invokust with MIT License | 5 votes |
def __init__(self, settings): self.settings = settings self.start_time = None self.end_time = None gevent.signal_handler(signal.SIGTERM, sig_term_handler)