本文整理汇总了Python中signal.ITIMER_PROF属性的典型用法代码示例。如果您正苦于以下问题:Python signal.ITIMER_PROF属性的具体用法?Python signal.ITIMER_PROF怎么用?Python signal.ITIMER_PROF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.ITIMER_PROF属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_itimer_prof
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [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)
示例2: run
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [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
示例3: test_itimer_prof
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [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)
示例4: sig_prof
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [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)
示例5: sig_prof
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [as 别名]
def sig_prof(self, *args):
self.hndl_called = True
signal.setitimer(signal.ITIMER_PROF, 0)
示例6: test_itimer_prof
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [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)
for i in xrange(100000000):
if signal.getitimer(self.itimer) == (0.0, 0.0):
break # sig_prof handler stopped this itimer
# profiling itimer should be (0.0, 0.0) now
self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0))
# and the handler should have been called
self.assertEqual(self.hndl_called, True)
示例7: set_timer_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import ITIMER_PROF [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."