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