本文整理汇总了Python中signal.SIGUSR1属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGUSR1属性的具体用法?Python signal.SIGUSR1怎么用?Python signal.SIGUSR1使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIGUSR1属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dd_iso_image_readoutput
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def dd_iso_image_readoutput(self, dd_process, gui_update, in_file_size,
output_q):
# If this time delay is not given, the Popen does not execute
# the actual command
time.sleep(0.1)
dd_process.send_signal(signal.SIGUSR1)
dd_process.stderr.flush()
while True:
time.sleep(0.1)
out_error = dd_process.stderr.readline().decode()
if out_error:
if 'bytes' in out_error:
bytes_copied = float(out_error.split(' ', 1)[0])
gui_update( bytes_copied / in_file_size * 100. )
break
if 15 < output_q.qsize():
output_q.get()
output_q.put(out_error.rstrip())
else:
# stderr is closed
break
示例2: test_poll_eintr
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def test_poll_eintr(self):
got_signal = [False]
def record(*args):
got_signal[0] = True
pid = os.getpid()
oldhandler = signal.signal(signal.SIGUSR1, record)
try:
killer = self.Process(target=self._killer, args=(pid,))
killer.start()
p = self.Process(target=time.sleep, args=(1,))
p.start()
p.join()
self.assertTrue(got_signal[0])
self.assertEqual(p.exitcode, 0)
killer.join()
finally:
signal.signal(signal.SIGUSR1, oldhandler)
#
# Test to verify handle verification, see issue 3321
#
示例3: test_ignore_listener
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def test_ignore_listener(self):
conn, child_conn = multiprocessing.Pipe()
try:
p = multiprocessing.Process(target=self._test_ignore_listener,
args=(child_conn,))
p.daemon = True
p.start()
child_conn.close()
address = conn.recv()
time.sleep(0.1)
os.kill(p.pid, signal.SIGUSR1)
time.sleep(0.1)
client = multiprocessing.connection.Client(address)
self.assertEqual(client.recv(), 'welcome')
p.join()
finally:
conn.close()
#
#
#
示例4: test_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [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()
示例5: run
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def run(self):
"""
Run guest main thread
"""
global virt
global exiting
virt = VirtioGuestPosix()
slave = Thread(target=worker, args=(virt,))
slave.start()
signal.signal(signal.SIGUSR1, sigusr_handler)
signal.signal(signal.SIGALRM, sigusr_handler)
while not exiting:
signal.alarm(1)
signal.pause()
catch = virt.catching_signal()
if catch:
signal.signal(signal.SIGIO, virt)
elif catch is False:
signal.signal(signal.SIGIO, signal.SIG_DFL)
if catch is not None:
virt.use_config.set()
print("PASS: guest_exit")
sys.exit(0)
示例6: test_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [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()
示例7: test_childSignalHandling
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def test_childSignalHandling(self):
"""
The disposition of signals which are ignored in the parent
process is reset to the default behavior for the child
process.
"""
# Somewhat arbitrarily select SIGUSR1 here. It satisfies our
# requirements that:
# - The interpreter not fiddle around with the handler
# behind our backs at startup time (this disqualifies
# signals like SIGINT and SIGPIPE).
# - The default behavior is to exit.
#
# This lets us send the signal to the child and then verify
# that it exits with a status code indicating that it was
# indeed the signal which caused it to exit.
which = signal.SIGUSR1
# Ignore the signal in the parent (and make sure we clean it
# up).
handler = signal.signal(which, signal.SIG_IGN)
self.addCleanup(signal.signal, signal.SIGUSR1, handler)
# Now do the test.
return self._testSignal(signal.SIGUSR1)
示例8: test_log
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [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)
示例9: test_pthread_kill_main_thread
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def test_pthread_kill_main_thread(self):
# Test that a signal can be sent to the main thread with pthread_kill()
# before any other thread has been created (see issue #12392).
code = """if True:
import threading
import signal
import sys
def handler(signum, frame):
sys.exit(3)
signal.signal(signal.SIGUSR1, handler)
signal.pthread_kill(threading.get_ident(), signal.SIGUSR1)
sys.exit(2)
"""
with spawn_python('-c', code) as process:
stdout, stderr = process.communicate()
exitcode = process.wait()
if exitcode != 3:
raise Exception("Child error (exit code %s): %s" %
(exitcode, stdout))
示例10: test_communicate_eintr
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def test_communicate_eintr(self):
# Issue #12493: communicate() should handle EINTR
def handler(signum, frame):
pass
old_handler = signal.signal(signal.SIGUSR1, handler)
self.addCleanup(signal.signal, signal.SIGUSR1, old_handler)
args = [sys.executable, "-c",
'import os, signal;'
'os.kill(os.getppid(), signal.SIGUSR1)']
for stream in ('stdout', 'stderr'):
kw = {stream: subprocess.PIPE}
with subprocess.Popen(args, **kw) as process:
# communicate() will be interrupted by SIGUSR1
process.communicate()
# This test is Linux-ish specific for simplicity to at least have
# some coverage. It is not a platform specific bug.
示例11: test_poll_eintr
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def test_poll_eintr(self):
got_signal = [False]
def record(*args):
got_signal[0] = True
pid = os.getpid()
oldhandler = signal.signal(signal.SIGUSR1, record)
try:
killer = self.Process(target=self._killer, args=(pid,))
killer.start()
try:
p = self.Process(target=time.sleep, args=(2,))
p.start()
p.join()
finally:
killer.join()
self.assertTrue(got_signal[0])
self.assertEqual(p.exitcode, 0)
finally:
signal.signal(signal.SIGUSR1, oldhandler)
#
# Test to verify handle verification, see issue 3321
#
示例12: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def __init__(self, app, call_id = 'GLOBAL', logfile = '/var/log/sip.log'):
self.itime = time()
self.app = '/%s' % app
self.call_id = call_id
bend = os.environ.get('SIPLOG_BEND', 'stderr').lower()
tform = os.environ.get('SIPLOG_TFORM', 'abs').lower()
if tform == 'rel':
self.offstime = True
itime = os.environ.get('SIPLOG_TSTART', self.itime)
self.itime = float(itime)
self.level = eval('SIPLOG_' + os.environ.get('SIPLOG_LVL', 'INFO'))
if bend == 'stderr':
self.write = self.write_stderr
elif bend == 'none':
self.write = self.donoting
else:
self.write = self.write_logfile
self.wi_available = Condition()
self.wi = []
if bend != 'syslog':
self.logger = AsyncLogger(app, self)
self.logfile = os.environ.get('SIPLOG_LOGFILE_FILE', logfile)
self.signal_handler = LogSignal(self, SIGUSR1, self.reopen)
else:
self.logger = AsyncLoggerSyslog(app, self)
self.app = ''
示例13: init_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def init_signals(self):
# Set up signals through the event loop API.
self.loop.add_signal_handler(
signal.SIGQUIT, self.handle_quit, signal.SIGQUIT, None
)
self.loop.add_signal_handler(
signal.SIGTERM, self.handle_exit, signal.SIGTERM, None
)
self.loop.add_signal_handler(
signal.SIGINT, self.handle_quit, signal.SIGINT, None
)
self.loop.add_signal_handler(
signal.SIGWINCH, self.handle_winch, signal.SIGWINCH, None
)
self.loop.add_signal_handler(
signal.SIGUSR1, self.handle_usr1, signal.SIGUSR1, None
)
self.loop.add_signal_handler(
signal.SIGABRT, self.handle_abort, signal.SIGABRT, None
)
# Don't let SIGTERM and SIGUSR1 disturb active requests
# by interrupting system calls
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
示例14: set_up_editor_wait
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [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)
示例15: kill_editor_wait
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGUSR1 [as 别名]
def kill_editor_wait(tmpdir):
"""Kill the waiting editor."""
pidfile = tmpdir / 'editor_pid'
pid = int(pidfile.read())
# windows has no SIGUSR1, 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.SIGUSR1)