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


Python gevent.signal方法代码示例

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


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

示例1: test_exitcode_previous_to_join

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def test_exitcode_previous_to_join(self):
        p = start_process(lambda: gevent.sleep(SHORTTIME))
        # Assume that the child process is still alive when the next
        # line is executed by the interpreter (there is no guarantee
        # for that, but it's rather likely).
        assert p.exitcode is None

        # Expect the child watcher mechanism to pick up
        # and process the child process termination event
        # (within at most two seconds). The `gevent.sleep()`
        # invocations allow for libev event loop iterations,
        # two of which are required after the OS delivers the
        # SIGCHLD signal to the parent process: one iteration
        # invokes the child reap loop, and the next invokes
        # the libev callback associated with the termination
        # event.
        deadline = time.time() + 2
        while time.time() < deadline:
            if p.exitcode is not None:
                assert p.exitcode == 0
                p.join()
                return
            gevent.sleep(ALMOSTZERO)
        raise Exception('Child termination not detected') 
开发者ID:jgehrcke,项目名称:gipc,代码行数:26,代码来源:test_gipc.py

示例2: test_early_readchild_exit_write_from_child

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def test_early_readchild_exit_write_from_child(self):
        pr = start_process(ipc_readonce_then_exit, (self.rh,))
        pw = start_process(ipc_endless_write_for_early_reader_exit, (self.wh,))
        # This test is to make sure equivalent behavior as in test
        # `test_early_readchild_exit` when the writing process is a
        # child process itself (above, the write process in the initial
        # process). Since gipc's child process creation
        # routine messes around with signal handlers, this test makes
        # sure that SIGPIPE is ignored in the child and that a
        # failing write attempt (after early read child exit) results
        # in an exception raised in the writing process.
        pr.join()
        pw.join()
        assert pr.exitcode == 0
        assert pw.exitcode == 0
        self.rh2.close()
        self.wh2.close() 
开发者ID:jgehrcke,项目名称:gipc,代码行数:19,代码来源:test_gipc.py

示例3: _install_signal_handlers

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def _install_signal_handlers(self):
        def request_force_stop():
            self.log.warning("Cold shut down.")
            self.gevent_pool.kill()
            raise SystemExit()

        def request_stop():
            if not self._stop_requested:
                gevent.signal(signal.SIGINT, request_force_stop)
                gevent.signal(signal.SIGTERM, request_force_stop)

                self.log.warning("Warm shut down requested.")
                self.log.warning(
                    "Stopping after all greenlets are finished. "
                    "Press Ctrl+C again for a cold shutdown."
                )

                self._stop_requested = True
                self.gevent_pool.join()
                if self.gevent_worker is not None:
                    self.gevent_worker.kill(StopRequested)

        gevent.signal(signal.SIGINT, request_stop)
        gevent.signal(signal.SIGTERM, request_stop) 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:26,代码来源:rq_gevent_worker.py

示例4: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def start(self):
        Jobmanager.start(self)

        if self.config['signal']:
            self.logger.info("Listening for push block notifs on signal {}"
                             .format(self.config['signal']))
            gevent.signal(self.config['signal'], self.getblocktemplate, signal=True)

        # Find desired auxmonitors
        self.config['merged'] = set(self.config['merged'])
        found_merged = set()

        for mon in self.manager.component_types['Jobmanager']:
            if mon.key in self.config['merged']:
                self.auxmons.append(mon)
                found_merged.add(mon.key)
                mon.new_job.rawlink(self.new_merged_work)

        for monitor in self.config['merged'] - found_merged:
            self.logger.error("Unable to locate Auxmonitor(s) '{}'".format(monitor)) 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:22,代码来源:monitor_network.py

示例5: serve_forever

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def serve_forever(self):
        gevent.signal(signal.SIGTERM, self.stop)
        gevent.signal(signal.SIGINT, self.stop)
        self.start()
        self._shutdown_event.wait() 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:7,代码来源:ServerRack.py

示例6: test_exitcode_sigkill

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def test_exitcode_sigkill(self):
        p = start_process(p_child_b)
        p.join()
        if not WINDOWS:
            assert p.exitcode == -signal.SIGKILL
        else:
            assert p.exitcode == 1
        _call_close_method_if_exists(p) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:10,代码来源:test_gipc.py

示例7: test_terminate

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def test_terminate(self):
        p = start_process(gevent.sleep, args=(1,))
        # Test __repr__ and __str__
        p.__repr__()
        p.terminate()
        p.join()
        p.__repr__()
        assert p.exitcode == -signal.SIGTERM
        _call_close_method_if_exists(p) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:11,代码来源:test_gipc.py

示例8: p_child_b

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def p_child_b():
    if not WINDOWS:
        os.kill(os.getpid(), signal.SIGKILL)
    else:
        sys.exit(1) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:7,代码来源:test_gipc.py

示例9: teardown

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def teardown(self):
        check_for_handles_left_open()
        # One could verify that signal handlers are not left improperly
        # by a test case, but libev's signal handling might go through
        # signalfd() which we cannot detect here anyway. So the test cases
        # have to properly clean up their signal handling modifications
        # themselves. 
开发者ID:jgehrcke,项目名称:gipc,代码行数:9,代码来源:test_gipc.py

示例10: test_orphaned_signal_watcher

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [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

示例11: test_signal_handlers_default

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def test_signal_handlers_default(self):
        p = start_process(signals_test_child_defaulthandlers)
        p.join()
        # Child exits normally when all signal dispositions are default.
        assert p.exitcode == 0 
开发者ID:jgehrcke,项目名称:gipc,代码行数:7,代码来源:test_gipc.py

示例12: signals_test_child_defaulthandlers

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def signals_test_child_defaulthandlers():
    for s in signals_to_reset:
        assert signal.getsignal(s) is signal.SIG_DFL 
开发者ID:jgehrcke,项目名称:gipc,代码行数:5,代码来源:test_gipc.py

示例13: build_mprpc_handler

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def build_mprpc_handler(server):
	global TO_EXIT
	TO_EXIT.append(server)

	def handler(signum=-1, frame=None):
		global INTERRUPTS
		INTERRUPTS += 1
		print('Signal handler called with signal %s for the %s time' % (signum, INTERRUPTS))
		if INTERRUPTS > 2:
			print("Raising due to repeat interrupts")
			raise KeyboardInterrupt
		for server in TO_EXIT:
			server.close()
	return handler 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:16,代码来源:server.py

示例14: run_rpc

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def run_rpc(interface_dict):
	print("MpRPC server Started.")
	server_instance = FetchInterfaceClass(interface_dict, "MpRPC")
	mprpc_server = StreamServer(('0.0.0.0', 4315), server_instance)

	gevent.signal(signal.SIGINT, build_mprpc_handler(mprpc_server))
	mprpc_server.serve_forever() 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:9,代码来源:server.py

示例15: _run_chassis

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import signal [as 别名]
def _run_chassis(fabricconfig, mgmtbusconfig, fts):
    try:
        # lower priority to make master and web
        # more "responsive"
        os.nice(5)

        c = minemeld.chassis.Chassis(
            fabricconfig['class'],
            fabricconfig['config'],
            mgmtbusconfig
        )
        c.configure(fts)

        gevent.signal(signal.SIGUSR1, c.stop)

        while not c.fts_init():
            if c.poweroff.wait(timeout=0.1) is not None:
                break

            gevent.sleep(1)

        LOG.info('Nodes initialized')

        try:
            c.poweroff.wait()
            LOG.info('power off')

        except KeyboardInterrupt:
            LOG.error("We should not be here !")
            c.stop()

    except:
        LOG.exception('Exception in chassis main procedure')
        raise 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:36,代码来源:launcher.py


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