當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.sigwait方法代碼示例

本文整理匯總了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) 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:23,代碼來源:container.py

示例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))
        ''') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:test_signal.py

示例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])
        """) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:31,代碼來源:test_signal.py

示例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))
        ''') 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:10,代碼來源:test_signal.py

示例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)) 
開發者ID:google,項目名稱:swift-jupyter,代碼行數:9,代碼來源:swift_kernel.py


注:本文中的signal.sigwait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。