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


Python signal.setitimer方法代码示例

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


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

示例1: sample

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def sample(self, signum, frame):  #pylint: disable=unused-argument
        """Samples current stack and writes result in self._stats.

        Args:
            signum: Signal that activates handler.
            frame: Frame on top of the stack when signal is handled.
        """
        stack = []
        while frame and frame != self.base_frame:
            stack.append((
                frame.f_code.co_name,
                frame.f_code.co_filename,
                frame.f_code.co_firstlineno))
            frame = frame.f_back
        self._stats[tuple(stack)] += 1
        signal.setitimer(signal.ITIMER_PROF, _SAMPLE_INTERVAL) 
开发者ID:nvdv,项目名称:vprof,代码行数:18,代码来源:flame_graph.py

示例2: sig_vtalrm

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def sig_vtalrm(self, *args):
        self.hndl_called = True

        if self.hndl_count > 3:
            # it shouldn't be here, because it should have been disabled.
            raise signal.ItimerError("setitimer didn't disable ITIMER_VIRTUAL "
                "timer.")
        elif self.hndl_count == 3:
            # disable ITIMER_VIRTUAL, this function shouldn't be called anymore
            signal.setitimer(signal.ITIMER_VIRTUAL, 0)
            if test_support.verbose:
                print("last SIGVTALRM handler call")

        self.hndl_count += 1

        if test_support.verbose:
            print("SIGVTALRM handler invoked", args) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_signal.py

示例3: test_itimer_prof

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def test_itimer_prof(self):
        self.itimer = signal.ITIMER_PROF
        signal.signal(signal.SIGPROF, self.sig_prof)
        signal.setitimer(self.itimer, 0.2, 0.2)

        start_time = time.time()
        while time.time() - start_time < 60.0:
            # do some work
            _ = pow(12345, 67890, 10000019)
            if signal.getitimer(self.itimer) == (0.0, 0.0):
                break # sig_prof handler stopped this itimer
        else: # Issue 8424
            self.skipTest("timeout: likely cause: machine too slow or load too "
                          "high")

        # profiling itimer should be (0.0, 0.0) now
        self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
        # and the handler should have been called
        self.assertEqual(self.hndl_called, True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_signal.py

示例4: run

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def run(self, profiler):
        weak_profiler = weakref.proxy(profiler)
        handle = functools.partial(self.handle_signal, weak_profiler)
        t = self.interval
        with deferral() as defer:
            prev_handle = signal.signal(signal.SIGPROF, handle)
            if prev_handle == signal.SIG_DFL:
                # sometimes the process receives SIGPROF although the sampler
                # unsets the itimer.  If the previous handler was SIG_DFL, the
                # process will crash when received SIGPROF.  To prevent this
                # risk, it makes the process to ignore SIGPROF when it isn't
                # running if the previous handler was SIG_DFL.
                prev_handle = signal.SIG_IGN
            defer(signal.signal, signal.SIGPROF, prev_handle)
            prev_itimer = signal.setitimer(signal.ITIMER_PROF, t, t)
            defer(signal.setitimer, signal.ITIMER_PROF, *prev_itimer)
            yield 
开发者ID:what-studio,项目名称:profiling,代码行数:19,代码来源:samplers.py

示例5: test_itimer_virtual

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def test_itimer_virtual(self):
        self.itimer = signal.ITIMER_VIRTUAL
        signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
        signal.setitimer(self.itimer, 0.3, 0.2)

        start_time = time.monotonic()
        while time.monotonic() - start_time < 60.0:
            # use up some virtual time by doing real work
            _ = pow(12345, 67890, 10000019)
            if signal.getitimer(self.itimer) == (0.0, 0.0):
                break # sig_vtalrm handler stopped this itimer
        else: # Issue 8424
            self.skipTest("timeout: likely cause: machine too slow or load too "
                          "high")

        # virtual itimer should be (0.0, 0.0) now
        self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
        # and the handler should have been called
        self.assertEqual(self.hndl_called, True)

    # Issue 3864, unknown if this affects earlier versions of freebsd also 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_signal.py

示例6: test_itimer_prof

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def test_itimer_prof(self):
        self.itimer = signal.ITIMER_PROF
        signal.signal(signal.SIGPROF, self.sig_prof)
        signal.setitimer(self.itimer, 0.2, 0.2)

        start_time = time.monotonic()
        while time.monotonic() - start_time < 60.0:
            # do some work
            _ = pow(12345, 67890, 10000019)
            if signal.getitimer(self.itimer) == (0.0, 0.0):
                break # sig_prof handler stopped this itimer
        else: # Issue 8424
            self.skipTest("timeout: likely cause: machine too slow or load too "
                          "high")

        # profiling itimer should be (0.0, 0.0) now
        self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
        # and the handler should have been called
        self.assertEqual(self.hndl_called, True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_signal.py

示例7: start

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [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

示例8: set_blocking_signal_threshold

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def set_blocking_signal_threshold(self, seconds, action):
        """Sends a signal if the ioloop is blocked for more than s seconds.

        Pass seconds=None to disable.  Requires python 2.6 on a unixy
        platform.

        The action parameter is a python signal handler.  Read the
        documentation for the python 'signal' module for more information.
        If action is None, the process will be killed if it is blocked for
        too long.
        """
        if not hasattr(signal, "setitimer"):
            #logging.error("set_blocking_signal_threshold requires a signal module "
            #           "with the setitimer method")
            ht.logger.error("set_blocking_signal_threshold requires a signal module "
                       "with the setitimer method")
            return
        self._blocking_signal_threshold = seconds
        if seconds is not None:
            signal.signal(signal.SIGALRM,
                          action if action is not None else signal.SIG_DFL) 
开发者ID:omererdem,项目名称:honeything,代码行数:23,代码来源:ioloop.py

示例9: set_blocking_signal_threshold

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def set_blocking_signal_threshold(self, seconds, action):
        if not hasattr(signal, "setitimer"):
            gen_log.error("set_blocking_signal_threshold requires a signal module "
                          "with the setitimer method")
            return
        self._blocking_signal_threshold = seconds
        if seconds is not None:
            signal.signal(signal.SIGALRM,
                          action if action is not None else signal.SIG_DFL) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:ioloop.py

示例10: __enter__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def __enter__(self):
        """Enables statistical profiler."""
        signal.signal(signal.SIGPROF, self.sample)
        signal.setitimer(signal.ITIMER_PROF, _SAMPLE_INTERVAL)
        self._start_time = time.time()
        return self 
开发者ID:nvdv,项目名称:vprof,代码行数:8,代码来源:flame_graph.py

示例11: __exit__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def __exit__(self, exc_type, exc_val, exc_tbf):
        """Disables statistical profiler."""
        self.run_time = time.time() - self._start_time
        signal.setitimer(signal.ITIMER_PROF, 0) 
开发者ID:nvdv,项目名称:vprof,代码行数:6,代码来源:flame_graph.py

示例12: __call__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def __call__(self, *args):
        # get the old SIGALRM handler
        old = signal.signal(signal.SIGALRM, self.handler)
        # set the alarm
        signal.setitimer(signal.ITIMER_REAL, self.timeout)
        try:
            result = self.function(*args)
        finally:
            # restore existing SIGALRM handler
            signal.signal(signal.SIGALRM, old)
        signal.setitimer(signal.ITIMER_REAL, 0)
        return result 
开发者ID:aerospike,项目名称:aerospike-admin,代码行数:14,代码来源:timeout.py

示例13: tearDown

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def tearDown(self):
        signal.signal(signal.SIGALRM, self.old_alarm)
        if self.itimer is not None: # test_itimer_exc doesn't change this attr
            # just ensure that itimer is stopped
            signal.setitimer(self.itimer, 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_signal.py

示例14: sig_prof

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def sig_prof(self, *args):
        self.hndl_called = True
        signal.setitimer(signal.ITIMER_PROF, 0)

        if test_support.verbose:
            print("SIGPROF handler invoked", args) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_signal.py

示例15: test_itimer_exc

# 需要导入模块: import signal [as 别名]
# 或者: from signal import setitimer [as 别名]
def test_itimer_exc(self):
        # XXX I'm assuming -1 is an invalid itimer, but maybe some platform
        # defines it ?
        self.assertRaises(signal.ItimerError, signal.setitimer, -1, 0)
        # Negative times are treated as zero on some platforms.
        if 0:
            self.assertRaises(signal.ItimerError,
                              signal.setitimer, signal.ITIMER_REAL, -1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_signal.py


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