当前位置: 首页>>代码示例>>Python>>正文


Python signal.SIGALRM属性代码示例

本文整理汇总了Python中signal.SIGALRM属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGALRM属性的具体用法?Python signal.SIGALRM怎么用?Python signal.SIGALRM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在signal的用法示例。


在下文中一共展示了signal.SIGALRM属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_communicate_eintr

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_communicate_eintr(self):
        # Issue #12493: communicate() should handle EINTR
        def handler(signum, frame):
            pass
        old_handler = signal.signal(signal.SIGALRM, handler)
        self.addCleanup(signal.signal, signal.SIGALRM, old_handler)

        # the process is running for 2 seconds
        args = [sys.executable, "-c", 'import time; time.sleep(2)']
        for stream in ('stdout', 'stderr'):
            kw = {stream: subprocess.PIPE}
            with subprocess.Popen(args, **kw) as process:
                signal.alarm(1)
                try:
                    # communicate() will be interrupted by SIGALRM
                    process.communicate()
                finally:
                    signal.alarm(0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_subprocess.py

示例2: __init__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def __init__(self):
        # Setup signal fd, this allows signal to behave correctly
        if os.name == 'posix':
            self.signal_pipe_r, self.signal_pipe_w = os.pipe()
            self._set_nonblock(self.signal_pipe_r)
            self._set_nonblock(self.signal_pipe_w)
            signal.set_wakeup_fd(self.signal_pipe_w)

        self._signals_received = collections.deque()

        signal.signal(signal.SIGINT, signal.SIG_DFL)
        if os.name == 'posix':
            signal.signal(signal.SIGCHLD, signal.SIG_DFL)
            signal.signal(signal.SIGTERM, self._signal_catcher)
            signal.signal(signal.SIGALRM, self._signal_catcher)
            signal.signal(signal.SIGHUP, self._signal_catcher)
        else:
            # currently a noop on window...
            signal.signal(signal.SIGTERM, self._signal_catcher)
            # FIXME(sileht): should allow to catch signal CTRL_BREAK_EVENT,
            # but we to create the child process with CREATE_NEW_PROCESS_GROUP
            # to make this work, so current this is a noop for later fix
            signal.signal(signal.SIGBREAK, self._signal_catcher) 
开发者ID:sileht,项目名称:cotyledon,代码行数:25,代码来源:_utils.py

示例3: _reproduce_preserved_alarm_stuff

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def _reproduce_preserved_alarm_stuff(self):
        preserved = self._preserved_alarm_data
        if preserved is not None:
            assert preserved.handler is not None
            # set the preserved handler as well as timeout and repeat
            # interval (if any; note: if the timeout has already passed
            # it will be set, by `_set_nonzero_alarm()`, to `MINIMAL_TIMEOUT`)
            self._signal(signal.SIGALRM, preserved.handler)
            if preserved.timeout:
                already_elapsed = time.time() - preserved.preserved_at
                self._store_alarm(preserved.timeout - already_elapsed, preserved.repeat_interval)
            else:
                self._store_alarm(0)
            self._clear_preserved_alarm_data()
        else:
            self._store_alarm(0) 
开发者ID:CERT-Polska,项目名称:n6,代码行数:18,代码来源:timeout_callback_manager.py

示例4: test_timeout_start

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_timeout_start(self, test_name, exc, assertion):
        """
        Tests running a timeout with the start method that will raise itself.
        """
        tsignal = signal.SIGALRM
        existing_handler = signal.getsignal(tsignal)
        t = QdbTimeout(1, exc)
        t.start()
        with self.assertRaises(Exception) as cm:
            self.assertTrue(t.pending)
            time.sleep(2)
            if exc:
                self.fail('Timeout did not stop the sleep')

        self.assertIs(cm.exception, exc or t)
        self.assertIs(signal.getsignal(tsignal), existing_handler) 
开发者ID:quantopian,项目名称:qdb,代码行数:18,代码来源:test_misc.py

示例5: test_timeout_ctx_mgr

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_timeout_ctx_mgr(self, test_name, exc, assertion):
        tsignal = signal.SIGALRM
        existing_handler = signal.getsignal(tsignal)
        try:
            with QdbTimeout(1, exc) as t:
                self.assertTrue(t.pending)
                time.sleep(2)
                if exc:
                    self.fail('Timeout did not stop the sleep')
        except Exception as u:
            assertion(self, u, t)
        else:
            self.assertIs(
                exc,
                False,
                'QdbTimeout(1, False) should not raise an exception'
            )

        self.assertIs(signal.getsignal(tsignal), existing_handler) 
开发者ID:quantopian,项目名称:qdb,代码行数:21,代码来源:test_misc.py

示例6: check_reentrant_write

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def check_reentrant_write(self, data, **fdopen_kwargs):
        def on_alarm(*args):
            # Will be called reentrantly from the same thread
            wio.write(data)
            1/0
        signal.signal(signal.SIGALRM, on_alarm)
        r, w = os.pipe()
        wio = self.io.open(w, **fdopen_kwargs)
        try:
            signal.alarm(1)
            # Either the reentrant call to wio.write() fails with RuntimeError,
            # or the signal handler raises ZeroDivisionError.
            with self.assertRaises((ZeroDivisionError, RuntimeError)) as cm:
                while 1:
                    for i in range(100):
                        wio.write(data)
                        wio.flush()
                    # Make sure the buffer doesn't fill up and block further writes
                    os.read(r, len(data) * 100)
            exc = cm.exception
            if isinstance(exc, RuntimeError):
                self.assertTrue(str(exc).startswith("reentrant call"), str(exc))
        finally:
            wio.close()
            os.close(r) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_io.py

示例7: test_select_interrupt_exc

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_select_interrupt_exc(self):
        s = self.SELECTOR()
        self.addCleanup(s.close)

        rd, wr = self.make_socketpair()

        class InterruptSelect(Exception):
            pass

        def handler(*args):
            raise InterruptSelect

        orig_alrm_handler = signal.signal(signal.SIGALRM, handler)
        self.addCleanup(signal.signal, signal.SIGALRM, orig_alrm_handler)
        self.addCleanup(signal.alarm, 0)

        signal.alarm(1)

        s.register(rd, selectors.EVENT_READ)
        t = time()
        # select() is interrupted by a signal which raises an exception
        with self.assertRaises(InterruptSelect):
            s.select(30)
        # select() was interrupted before the timeout of 30 seconds
        self.assertLess(time() - t, 5.0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_selectors.py

示例8: test_select_interrupt_noraise

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_select_interrupt_noraise(self):
        s = self.SELECTOR()
        self.addCleanup(s.close)

        rd, wr = self.make_socketpair()

        orig_alrm_handler = signal.signal(signal.SIGALRM, lambda *args: None)
        self.addCleanup(signal.signal, signal.SIGALRM, orig_alrm_handler)
        self.addCleanup(signal.alarm, 0)

        signal.alarm(1)

        s.register(rd, selectors.EVENT_READ)
        t = time()
        # select() is interrupted by a signal, but the signal handler doesn't
        # raise an exception, so select() should by retries with a recomputed
        # timeout
        self.assertFalse(s.select(1.5))
        self.assertGreaterEqual(time() - t, 1.0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_selectors.py

示例9: test_rlock_acquire_interruption

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_rlock_acquire_interruption(self):
        # Mimic receiving a SIGINT (KeyboardInterrupt) with SIGALRM while stuck
        # in a deadlock.
        # XXX this test can fail when the legacy (non-semaphore) implementation
        # of locks is used in thread_pthread.h, see issue #11223.
        oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt)
        try:
            rlock = thread.RLock()
            # For reentrant locks, the initial acquisition must be in another
            # thread.
            def other_thread():
                rlock.acquire()
            thread.start_new_thread(other_thread, ())
            # Wait until we can't acquire it without blocking...
            while rlock.acquire(blocking=False):
                rlock.release()
                time.sleep(0.01)
            signal.alarm(1)
            t1 = time.time()
            self.assertRaises(KeyboardInterrupt, rlock.acquire, timeout=5)
            dt = time.time() - t1
            # See rationale above in test_lock_acquire_interruption
            self.assertLess(dt, 3.0)
        finally:
            signal.signal(signal.SIGALRM, oldalrm) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_threadsignals.py

示例10: start

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def start(self):
        self.last_profile_time = timer()

        if self.use_signal:
            try:
                signal.signal(signal.SIGALRM, self._signal)
                # the following tells the system to restart interrupted system calls if they are
                # interrupted before any data has been transferred. This avoids many of the problems
                # related to signals interrupting system calls, see issue #16
                signal.siginterrupt(signal.SIGALRM, False)
            except ValueError:
                raise NotMainThreadError()

            signal.setitimer(signal.ITIMER_REAL, self.interval, 0.0)
        else:
            sys.setprofile(self._profile) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:18,代码来源:profiler.py

示例11: setUp

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def setUp(self):
        # isatty() and close() can hang on some platforms.  Set an alarm
        # before running the test to make sure we don't hang forever.
        old_alarm = signal.signal(signal.SIGALRM, self.handle_sig)
        self.addCleanup(signal.signal, signal.SIGALRM, old_alarm)
        self.addCleanup(signal.alarm, 0)
        signal.alarm(10) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_pty.py

示例12: registerSignals

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def registerSignals(for_usr1, for_usr2, for_alrm):
    usr1 = signal.signal(signal.SIGUSR1, for_usr1)
    usr2 = signal.signal(signal.SIGUSR2, for_usr2)
    alrm = signal.signal(signal.SIGALRM, for_alrm)
    return usr1, usr2, alrm


# The signal handler. Just note that the signal occurred and
# from who. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_threadsignals.py

示例13: test_main

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def test_main():
    global signal_blackboard

    signal_blackboard = { signal.SIGUSR1 : {'tripped': 0, 'tripped_by': 0 },
                          signal.SIGUSR2 : {'tripped': 0, 'tripped_by': 0 },
                          signal.SIGALRM : {'tripped': 0, 'tripped_by': 0 } }

    oldsigs = registerSignals(handle_signals, handle_signals, handle_signals)
    try:
        run_unittest(ThreadSignals)
    finally:
        registerSignals(*oldsigs) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_threadsignals.py

示例14: timeout

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def timeout(seconds):
    if not seconds:
        yield
        return
    
    original_handler = signal(SIGALRM, noop)

    try:
        alarm(seconds)
        yield
    finally:
        alarm(0)
        signal(SIGALRM, original_handler) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:15,代码来源:timeout.py

示例15: limitedTime

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGALRM [as 别名]
def limitedTime(second, func, *args, **kw):
            second = fixTimeout(second)
            old_alarm = signal(SIGALRM, signalHandler)
            try:
                alarm(second)
                return func(*args, **kw)
            finally:
                alarm(0)
                signal(SIGALRM, old_alarm) 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:11,代码来源:timeout.py


注:本文中的signal.SIGALRM属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。