本文整理汇总了Python中signal.sigwait方法的典型用法代码示例。如果您正苦于以下问题:Python signal.sigwait方法的具体用法?Python signal.sigwait怎么用?Python signal.sigwait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类signal
的用法示例。
在下文中一共展示了signal.sigwait方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_for_child_and_forward_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import sigwait [as 别名]
def wait_for_child_and_forward_signals(child_pid, process_name):
"""Wait for a child to terminate and in the meantime forward all signals
that the current process receives to this child.
@return a tuple of exit code and resource usage of the child as given by os.waitpid
"""
block_all_signals()
while True:
logging.debug("Waiting for signals")
signum = signal.sigwait(_ALL_SIGNALS)
if signum == signal.SIGCHLD:
pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)
while pid != 0:
if pid == child_pid:
return exitcode, ru_child
else:
logging.debug("Received unexpected SIGCHLD for PID %s", pid)
pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)
else:
_forward_signal(signum, child_pid, process_name)
示例2: test_sigwait
# 需要导入模块: import signal [as 别名]
# 或者: from signal import sigwait [as 别名]
def test_sigwait(self):
self.wait_helper(signal.SIGALRM, '''
def test(signum):
signal.alarm(1)
received = signal.sigwait([signum])
assert isinstance(received, signal.Signals), received
if received != signum:
raise Exception('received %s, not %s' % (received, signum))
''')
示例3: test_sigwait_thread
# 需要导入模块: import signal [as 别名]
# 或者: from signal import sigwait [as 别名]
def test_sigwait_thread(self):
# Check that calling sigwait() from a thread doesn't suspend the whole
# process. A new interpreter is spawned to avoid problems when mixing
# threads and fork(): only async-safe functions are allowed between
# fork() and exec().
assert_python_ok("-c", """if True:
import os, threading, sys, time, signal
# the default handler terminates the process
signum = signal.SIGUSR1
def kill_later():
# wait until the main thread is waiting in sigwait()
time.sleep(1)
os.kill(os.getpid(), signum)
# the signal must be blocked by all the threads
signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
killer = threading.Thread(target=kill_later)
killer.start()
received = signal.sigwait([signum])
if received != signum:
print("sigwait() received %s, not %s" % (received, signum),
file=sys.stderr)
sys.exit(1)
killer.join()
# unblock the signal, which should have been cleared by sigwait()
signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
""")
示例4: test_sigwait
# 需要导入模块: import signal [as 别名]
# 或者: from signal import sigwait [as 别名]
def test_sigwait(self):
self.wait_helper(signal.SIGALRM, '''
def test(signum):
signal.alarm(1)
received = signal.sigwait([signum])
if received != signum:
raise Exception('received %s, not %s' % (received, signum))
''')
示例5: run
# 需要导入模块: import signal [as 别名]
# 或者: from signal import sigwait [as 别名]
def run(self):
try:
while True:
signal.sigwait([signal.SIGINT])
self.kernel.process.SendAsyncInterrupt()
except Exception as e:
self.kernel.log.error('Exception in SIGINTHandler: %s' % str(e))