当前位置: 首页>>代码示例>>Python>>正文


Python gevent.signal_handler方法代码示例

本文整理汇总了Python中gevent.signal_handler方法的典型用法代码示例。如果您正苦于以下问题:Python gevent.signal_handler方法的具体用法?Python gevent.signal_handler怎么用?Python gevent.signal_handler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gevent的用法示例。


在下文中一共展示了gevent.signal_handler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install_signal_handlers

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal_handler [as 别名]
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) 
开发者ID:pricingassistant,项目名称:mrq,代码行数:24,代码来源:processes.py

示例2: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal_handler [as 别名]
def __init__(self, settings):
        self.settings = settings
        self.start_time = None
        self.end_time = None
        gevent.signal_handler(signal.SIGTERM, sig_term_handler) 
开发者ID:FutureSharks,项目名称:invokust,代码行数:7,代码来源:loadtest.py

示例3: test_orphaned_signal_watcher

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal_handler [as 别名]
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() 
开发者ID:jgehrcke,项目名称:gipc,代码行数:38,代码来源:test_gipc.py


注:本文中的gevent.signal_handler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。