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


Python signal.ITIMER_REAL屬性代碼示例

本文整理匯總了Python中signal.ITIMER_REAL屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.ITIMER_REAL屬性的具體用法?Python signal.ITIMER_REAL怎麽用?Python signal.ITIMER_REAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在signal的用法示例。


在下文中一共展示了signal.ITIMER_REAL屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: measure_itimer_resolution

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def measure_itimer_resolution(self):
        N = 20
        times = []

        def handler(signum=None, frame=None):
            if len(times) < N:
                times.append(time.perf_counter())
                # 1 µs is the smallest possible timer interval,
                # we want to measure what the concrete duration
                # will be on this platform
                signal.setitimer(signal.ITIMER_REAL, 1e-6)

        self.addCleanup(signal.setitimer, signal.ITIMER_REAL, 0)
        self.setsig(signal.SIGALRM, handler)
        handler()
        while len(times) < N:
            time.sleep(1e-3)

        durations = [times[i+1] - times[i] for i in range(len(times) - 1)]
        med = statistics.median(durations)
        if support.verbose:
            print("detected median itimer() resolution: %.6f s." % (med,))
        return med 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:25,代碼來源:test_signal.py

示例2: test_itimer_exc

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [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

示例3: test_itimer_real

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def test_itimer_real(self):
        self.itimer = signal.ITIMER_REAL
        signal.setitimer(self.itimer, 1.0)
        if test_support.verbose:
            print("\ncall pause()...")
        signal.pause()

        self.assertEqual(self.hndl_called, True)

    # Issue 3864. Unknown if this affects earlier versions of freebsd also. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_signal.py

示例4: test_setitimer_tiny

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def test_setitimer_tiny(self):
        # bpo-30807: C setitimer() takes a microsecond-resolution interval.
        # Check that float -> timeval conversion doesn't round
        # the interval down to zero, which would disable the timer.
        self.itimer = signal.ITIMER_REAL
        signal.setitimer(self.itimer, 1e-6)
        time.sleep(1)
        self.assertEqual(self.hndl_called, True) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_signal.py

示例5: _set_nonzero_alarm

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def _set_nonzero_alarm(cls, timeout, repeat_interval=0):
        actual_timeout = max(cls.MINIMAL_TIMEOUT, timeout)
        cls._setitimer(signal.ITIMER_REAL, actual_timeout, repeat_interval) 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:5,代碼來源:timeout_callback_manager.py

示例6: _unset_alarm

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def _unset_alarm(cls):
        return cls._setitimer(signal.ITIMER_REAL, 0) 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:4,代碼來源:timeout_callback_manager.py

示例7: test_itimer_real

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def test_itimer_real(self):
        self.itimer = signal.ITIMER_REAL
        signal.setitimer(self.itimer, 1.0)
        signal.pause()
        self.assertEqual(self.hndl_called, True)

    # Issue 3864, unknown if this affects earlier versions of freebsd also 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_signal.py

示例8: test_itimer_real

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def test_itimer_real(self):
        self.itimer = signal.ITIMER_REAL
        signal.setitimer(self.itimer, 1.0)
        if test_support.verbose:
            print("\ncall pause()...")
        signal.pause()

        self.assertEqual(self.hndl_called, True) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:10,代碼來源:test_signal.py

示例9: set_timer_signal

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def set_timer_signal(use_wallclock_time: bool = False) -> None:
        """Set up timer signals for CPU profiling."""
        if use_wallclock_time:
            Scalene.__cpu_timer_signal = signal.ITIMER_REAL
        else:
            Scalene.__cpu_timer_signal = signal.ITIMER_VIRTUAL

        # Now set the appropriate timer signal.
        if Scalene.__cpu_timer_signal == signal.ITIMER_REAL:
            Scalene.__cpu_signal = signal.SIGALRM
        elif Scalene.__cpu_timer_signal == signal.ITIMER_VIRTUAL:
            Scalene.__cpu_signal = signal.SIGVTALRM
        elif Scalene.__cpu_timer_signal == signal.ITIMER_PROF:
            # NOT SUPPORTED
            assert False, "ITIMER_PROF is not currently supported." 
開發者ID:emeryberger,項目名稱:scalene,代碼行數:17,代碼來源:scalene.py

示例10: test_stress_delivery_dependent

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_REAL [as 別名]
def test_stress_delivery_dependent(self):
        """
        This test uses dependent signal handlers.
        """
        N = self.decide_itimer_count()
        sigs = []

        def first_handler(signum, frame):
            # 1e-6 is the minimum non-zero value for `setitimer()`.
            # Choose a random delay so as to improve chances of
            # triggering a race condition.  Ideally the signal is received
            # when inside critical signal-handling routines such as
            # Py_MakePendingCalls().
            signal.setitimer(signal.ITIMER_REAL, 1e-6 + random.random() * 1e-5)

        def second_handler(signum=None, frame=None):
            sigs.append(signum)

        # Here on Linux, SIGPROF > SIGALRM > SIGUSR1.  By using both
        # ascending and descending sequences (SIGUSR1 then SIGALRM,
        # SIGPROF then SIGALRM), we maximize chances of hitting a bug.
        self.setsig(signal.SIGPROF, first_handler)
        self.setsig(signal.SIGUSR1, first_handler)
        self.setsig(signal.SIGALRM, second_handler)  # for ITIMER_REAL

        expected_sigs = 0
        deadline = time.monotonic() + 15.0

        while expected_sigs < N:
            os.kill(os.getpid(), signal.SIGPROF)
            expected_sigs += 1
            # Wait for handlers to run to avoid signal coalescing
            while len(sigs) < expected_sigs and time.monotonic() < deadline:
                time.sleep(1e-5)

            os.kill(os.getpid(), signal.SIGUSR1)
            expected_sigs += 1
            while len(sigs) < expected_sigs and time.monotonic() < deadline:
                time.sleep(1e-5)

        # All ITIMER_REAL signals should have been delivered to the
        # Python handler
        self.assertEqual(len(sigs), N, "Some signals were lost") 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:45,代碼來源:test_signal.py


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