当前位置: 首页>>代码示例>>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;未经允许,请勿转载。