當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。