本文整理匯總了Python中signal.ITIMER_VIRTUAL屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.ITIMER_VIRTUAL屬性的具體用法?Python signal.ITIMER_VIRTUAL怎麽用?Python signal.ITIMER_VIRTUAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類signal
的用法示例。
在下文中一共展示了signal.ITIMER_VIRTUAL屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sig_vtalrm
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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)
示例2: test_itimer_virtual
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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.time()
while time.time() - 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.
示例3: test_itimer_virtual
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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
示例4: test_itimer_virtual
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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.time()
while time.time() - 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
示例5: test_itimer_virtual
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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)
示例6: sig_vtalrm
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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)
self.hndl_count += 1
示例7: test_itimer_virtual
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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)
for i in xrange(100000000):
if signal.getitimer(self.itimer) == (0.0, 0.0):
break # sig_vtalrm handler stopped this itimer
# virtual 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.assertEquals(self.hndl_called, True)
示例8: set_timer_signal
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [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."
示例9: gettime
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import ITIMER_VIRTUAL [as 別名]
def gettime() -> float:
"""High-precision timer of time spent running in or on behalf of this
process."""
if Scalene.__cpu_timer_signal == signal.ITIMER_VIRTUAL:
# Using virtual time
return time.process_time()
else:
# Using wall clock time
return time.perf_counter()