本文整理匯總了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')
示例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()
示例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)
示例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))
示例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()
示例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)
示例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)
示例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)
示例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.
示例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()
示例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
示例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
示例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
示例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()
示例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