本文整理匯總了Python中signal.SIGUSR2屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.SIGUSR2屬性的具體用法?Python signal.SIGUSR2怎麽用?Python signal.SIGUSR2使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類signal
的用法示例。
在下文中一共展示了signal.SIGUSR2屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def test_signals(self):
signalled_all.acquire()
self.spawnSignallingThread()
signalled_all.acquire()
# the signals that we asked the kernel to send
# will come back, but we don't know when.
# (it might even be after the thread exits
# and might be out of order.) If we haven't seen
# the signals yet, send yet another signal and
# wait for it return.
if signal_blackboard[signal.SIGUSR1]['tripped'] == 0 \
or signal_blackboard[signal.SIGUSR2]['tripped'] == 0:
try:
signal.alarm(1)
signal.pause()
finally:
signal.alarm(0)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped_by'],
thread.get_ident())
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped_by'],
thread.get_ident())
signalled_all.release()
示例2: test_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def test_signals(self):
signalled_all.acquire()
self.spawnSignallingThread()
signalled_all.acquire()
# the signals that we asked the kernel to send
# will come back, but we don't know when.
# (it might even be after the thread exits
# and might be out of order.) If we haven't seen
# the signals yet, send yet another signal and
# wait for it return.
if signal_blackboard[signal.SIGUSR1]['tripped'] == 0 \
or signal_blackboard[signal.SIGUSR2]['tripped'] == 0:
signal.alarm(1)
signal.pause()
signal.alarm(0)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped_by'],
thread.get_ident())
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped_by'],
thread.get_ident())
signalled_all.release()
示例3: shutdown
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def shutdown(self):
if self.launched:
self.semaphore.acquire()
self.child.kill(signal.SIGUSR2)
# wait for rtkrcv to shutdown
try:
self.child.wait()
except pexpect.ExceptionPexpect:
print("Already dead!!")
if self.child.isalive():
r = -1
else:
r = 1
self.semaphore.release()
self.launched = False
return r
# already shut down
return 2
示例4: test_log
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def test_log(self):
"""Logging tests"""
# Not much to test here but exercise the code nonetheless
# for regression/coverage.
log = Log(verbose=False, prefix='test')
log.debug("Invisible debug.")
try:
raise ValueError("Test exception")
except ValueError:
log.exception("Test exception with message")
for num in range(1, 5):
log.debug("Debug")
log.info("Info")
log.warning("Warning")
log.error("Error")
log.critical("Crtitical")
os.kill(os.getpid(),
signal.SIGUSR1 if (num % 2) != 0 else signal.SIGUSR2)
示例5: MockTracer
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def MockTracer(self):
"""
Construct a mock tracer.
"""
tracer = MagicMock()
tracer.address = self.tracer_host, self.tracer_port
tracer.pause_signal = signal.SIGUSR2
tracer.retry_attempts = 1
tracer.local = 0, 0
tracer.uuid = 'mock'
tracer.watchlist = {}
tracer.curframe = sys._getframe()
tracer.stack = [(sys._getframe(), 1)] * 3
tracer.skip_fn = lambda _: False
tracer.cmd_manager = self.cmd_manager
return tracer
示例6: __init__
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def __init__(self):
self.signals = {
'reload_conf_pending': False,
'interrupted': False,
'open_backdoor': False,
'orig': {
signal.SIGINT: None,
signal.SIGTERM: None,
}
}
try:
self.signals['orig'].update({
signal.SIGUSR1: None,
signal.SIGUSR2: None,
})
except AttributeError:
# Unavailable on Windows
pass
示例7: test_register_signal_handler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def test_register_signal_handler(
self,
patch_config,
patch_db_connections,
patch_restarter,
patch_signal,
patch_running,
patch_producer,
patch_exit,
):
patch_running.return_value = False
replication_stream = self._init_and_run_batch()
# ZKLock also calls patch_signal, so we have to work around it
assert [
mock.call(signal.SIGINT, replication_stream._handle_shutdown_signal),
mock.call(signal.SIGTERM, replication_stream._handle_shutdown_signal),
mock.call(signal.SIGUSR2, replication_stream._handle_profiler_signal),
] in patch_signal.call_args_list
示例8: set_up_editor_wait
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def set_up_editor_wait(quteproc, tmpdir, text, editor_pid_watcher):
"""Set up editor.command to a small python script inserting a text."""
assert not utils.is_windows
pidfile = tmpdir / 'editor_pid'
script = tmpdir / 'script.py'
script.write(textwrap.dedent("""
import os
import sys
import time
import signal
def handle(sig, _frame):
filename = sys.argv[1]
old_mtime = new_mtime = os.stat(filename).st_mtime
while old_mtime == new_mtime:
time.sleep(0.1)
with open(filename, 'w', encoding='utf-8') as f:
f.write({text!r})
new_mtime = os.stat(filename).st_mtime
if sig == signal.SIGUSR1:
sys.exit(0)
signal.signal(signal.SIGUSR1, handle)
signal.signal(signal.SIGUSR2, handle)
with open(r'{pidfile}', 'w') as f:
f.write(str(os.getpid()))
time.sleep(100)
""".format(pidfile=pidfile, text=text)))
editor = json.dumps([sys.executable, str(script), '{}'])
quteproc.set_setting('editor.command', editor)
示例9: save_editor_wait
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def save_editor_wait(tmpdir):
"""Trigger the waiting editor to write without exiting."""
pidfile = tmpdir / 'editor_pid'
# give the "editor" process time to write its pid
for _ in range(10):
if pidfile.check():
break
time.sleep(1)
pid = int(pidfile.read())
# windows has no SIGUSR2, but we don't run this on windows anyways
# for posix, there IS a member so we need to ignore useless-suppression
# pylint: disable=no-member,useless-suppression
os.kill(pid, signal.SIGUSR2)
示例10: sigusr_handler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def sigusr_handler(_signo, _stack_frame):
if _signo == signal.SIGUSR1:
emit(jvm={"errors": 1.0})
elif _signo == signal.SIGUSR2:
emit(jvm={"ooms": 1.0})
else:
# Should not happen
pass
m2ee.stop()
sys.exit(1)
示例11: registerSignals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def registerSignals(for_usr1, for_usr2, for_alrm):
usr1 = signal.signal(signal.SIGUSR1, for_usr1)
usr2 = signal.signal(signal.SIGUSR2, for_usr2)
alrm = signal.signal(signal.SIGALRM, for_alrm)
return usr1, usr2, alrm
# The signal handler. Just note that the signal occurred and
# from who.
示例12: send_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def send_signals():
os.kill(process_pid, signal.SIGUSR1)
os.kill(process_pid, signal.SIGUSR2)
signalled_all.release()
示例13: test_main
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def test_main():
global signal_blackboard
signal_blackboard = { signal.SIGUSR1 : {'tripped': 0, 'tripped_by': 0 },
signal.SIGUSR2 : {'tripped': 0, 'tripped_by': 0 },
signal.SIGALRM : {'tripped': 0, 'tripped_by': 0 } }
oldsigs = registerSignals(handle_signals, handle_signals, handle_signals)
try:
run_unittest(ThreadSignals)
finally:
registerSignals(*oldsigs)
示例14: configure_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def configure_signals(): # pragma: no cover
'''
Configure borgmatic's signal handlers to pass relevant signals through to any child processes
like Borg. Note that SIGINT gets passed through even without these changes.
'''
for signal_number in (signal.SIGHUP, signal.SIGTERM, signal.SIGUSR1, signal.SIGUSR2):
signal.signal(signal_number, _handle_signal)
示例15: stop
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGUSR2 [as 別名]
def stop(self):
# terminate the stream
if self.started:
self.child.kill(signal.SIGUSR2)
try:
self.child.wait()
except pexpect.ExceptionPexpect:
print("Str2str already down")
self.started = False
return 1
# str2str already stopped
return 2