本文整理匯總了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))