本文整理汇总了Python中signal.pause方法的典型用法代码示例。如果您正苦于以下问题:Python signal.pause方法的具体用法?Python signal.pause怎么用?Python signal.pause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类signal
的用法示例。
在下文中一共展示了signal.pause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def test_signals(self):
signalled_all.acquire()
self.spawnSignallingThread()
signalled_all.acquire()
# the signals that we asked the kernel to send
# will come back, but we don't know when.
# (it might even be after the thread exits
# and might be out of order.) If we haven't seen
# the signals yet, send yet another signal and
# wait for it return.
if signal_blackboard[signal.SIGUSR1]['tripped'] == 0 \
or signal_blackboard[signal.SIGUSR2]['tripped'] == 0:
try:
signal.alarm(1)
signal.pause()
finally:
signal.alarm(0)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped_by'],
thread.get_ident())
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped_by'],
thread.get_ident())
signalled_all.release()
示例2: run
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def run(self):
"""
Run guest main thread
"""
global virt
global exiting
virt = VirtioGuestPosix()
slave = Thread(target=worker, args=(virt,))
slave.start()
signal.signal(signal.SIGUSR1, sigusr_handler)
signal.signal(signal.SIGALRM, sigusr_handler)
while not exiting:
signal.alarm(1)
signal.pause()
catch = virt.catching_signal()
if catch:
signal.signal(signal.SIGIO, virt)
elif catch is False:
signal.signal(signal.SIGIO, signal.SIG_DFL)
if catch is not None:
virt.use_config.set()
print("PASS: guest_exit")
sys.exit(0)
示例3: test_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def test_signals(self):
signalled_all.acquire()
self.spawnSignallingThread()
signalled_all.acquire()
# the signals that we asked the kernel to send
# will come back, but we don't know when.
# (it might even be after the thread exits
# and might be out of order.) If we haven't seen
# the signals yet, send yet another signal and
# wait for it return.
if signal_blackboard[signal.SIGUSR1]['tripped'] == 0 \
or signal_blackboard[signal.SIGUSR2]['tripped'] == 0:
signal.alarm(1)
signal.pause()
signal.alarm(0)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped_by'],
thread.get_ident())
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped_by'],
thread.get_ident())
signalled_all.release()
示例4: wait_for_shutdown_event
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def wait_for_shutdown_event(self):
self._event = threading.Event()
# Since signal.pause() is not avaialble on windows, use event.wait()
# with a timeout to catch KeyboardInterrupt. Without timeout, it"s
# not possible to catch KeyboardInterrupt because event.wait() is
# a blocking call without timeout. The if condition checks if the os
# is windows.
if os.name == "nt":
while True:
try:
self._event.wait(1)
except (KeyboardInterrupt, SystemExit) as e:
print("Controller shutdown event: {0}".format(str(e)))
break
else:
for sig in [signal.SIGINT, signal.SIGTERM]:
signal.signal(sig, CFX.__handler)
# sleeps until signal is received
# pylint: disable=no-member
signal.pause()
示例5: main
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def main(args):
print "Starting cluster simulation..."
simulator = ClusterSimulation.Simulator.createGlobalSimulator()
simulator.startService()
simulator.desirePublisher.desireNumberOfWorkers(1)
def signal_handler(sig, _):
signal_name = '(unknown)'
if sig == signal.SIGINT:
signal_name = 'SIGINT'
elif sig == signal.SIGTERM:
signal_name = 'SIGTERM'
print 'Received ', signal_name, 'signal. Exiting.'
simulator.stopService()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
print "Press Ctrl+C to exit."
signal.pause()
示例6: startSharedState
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def startSharedState(args):
if parsed.cacheDir:
logging.info("Shared state cache directory: %s", parsed.cacheDir)
Setup.config().sharedStateCache = parsed.cacheDir
service = SharedStateService.SharedStateService(callbackScheduler)
service.startService()
service.blockUntilListening()
def handleSigTerm(signum, frame):
logging.info("SIGTERM received - shutting down")
service.stopService()
signal.signal(signal.SIGTERM, handleSigTerm)
signal.pause()
logging.info("process exiting")
示例7: main
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def main(args):
print "ufora-worker starting"
setup = defaultSetup()
with Setup.PushSetup(setup):
setup.config.configureLoggingForBackgroundProgram()
worker = createService(args)
worker.startService(None)
def signal_handler(sig, _):
signal_name = '(unknown)'
if sig == signal.SIGINT:
signal_name = 'SIGINT'
elif sig == signal.SIGTERM:
signal_name = 'SIGTERM'
print 'Received ', signal_name, 'signal. Exiting.'
worker.stopService()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
print "Press Ctrl+C to exit."
signal.pause()
示例8: main
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def main(args):
print "ufora-gateway starting"
worker = createService(args)
worker.startService(None)
def signal_handler(sig, _):
signal_name = '(unknown)'
if sig == signal.SIGINT:
signal_name = 'SIGINT'
elif sig == signal.SIGTERM:
signal_name = 'SIGTERM'
print 'Received ', signal_name, 'signal. Exiting.'
worker.stopService()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
print "Press Ctrl+C to exit."
signal.pause()
示例9: test_z_alarm
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def test_z_alarm(self):
global s
signal.signal(signal.SIGALRM, catcher)
print('Setting alarm for 0.3 seconds')
start = s = time.time()
itimer.alarm(0.3)
signal.pause()
self.assertAlmostEqual(time.time()-start, 0.3, places=2)
print('Setting alarm for 1.1 seconds')
start = s = time.time()
itimer.alarm(1.1)
signal.pause()
self.assertAlmostEqual(time.time()-start, 1.1, places=2)
print('Setting alarm for 5.5 seconds')
start = s = time.time()
itimer.alarm(5.5)
signal.pause()
self.assertAlmostEqual(time.time()-start, 5.5, places=2)
itimer.alarm(0)
olddelay, oldinterval = itimer.getitimer(itimer.ITIMER_REAL)
self.assertEqual(olddelay, 0.0)
self.assertEqual(oldinterval, 0.0)
示例10: main
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def main(listen_addrs=['127.0.0.1:9901']):
s = create_server(listen_addrs)
print("Server created on", listen_addrs)
s.start()
print("Server started")
import signal
old1 = signal.signal(signal.SIGINT, signal_handler)
old2 = signal.signal(signal.SIGTERM, signal_handler)
import time
# signal.pause is not valid in windows
try:
while True:
time.sleep(3600 * 24)
except QuitException:
print("Quit server")
shutdown_event = s.stop(5)
shutdown_event.wait()
finally:
signal.signal(signal.SIGINT, old1)
signal.signal(signal.SIGTERM, old2)
示例11: pause_children
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def pause_children(self, names=None):
# send pause signal to alive children
if names is None:
names = self.conns_from_children.keys()
logger.debug("Pausing %s", str(names))
for name in names:
assert name in self.child_states # check it's a real child
proc = self.child_processes[name]
if proc.is_alive():
try:
process = psutil.Process(pid=proc.pid)
try:
for child in process.children(recursive=True):
try:
child.send_signal(signal.SIGTSTP)
except (psutil.NoSuchProcess, psutil.AccessDenied, IOError):
pass
except (psutil.NoSuchProcess, psutil.AccessDenied, IOError) as e:
logger.warn("Error %s getting children for pause for child %s", e.strerror, name)
process.send_signal(signal.SIGTSTP)
logger.info("Paused %s", name)
except (psutil.NoSuchProcess, psutil.AccessDenied, IOError): # child may have terminated
pass
示例12: sleep
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def sleep(self, seconds):
"""Sleeps for at most the specified number of seconds while also handling signals.
Python does not do a great job of handling signals quickly when you invoke the normal time.sleep().
This method is a Unix-specific implementation of a sleep that should do better quickly handling signals while
sleeping.
This method may return earlier than the requested number of seconds if a signal is received.
@param seconds: The number of seconds to sleep for.
"""
# We schedule an alarm signal for x=seconds out in the future.
# noinspection PyUnusedLocal
def handle_alarm(signal_num, frame):
pass
signal.signal(signal.SIGALRM, handle_alarm)
signal.alarm(seconds)
# Wait for either the alarm to go off or for us to receive a SIGINT.
signal.pause()
# Remove the alarm if it is still pending.
signal.alarm(0)
示例13: stop
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def stop(self):
"""Spops all animation"""
self._setup_gpio()
if self.fading:
self.fader.stop()
self.fading = False
if self.pulsing:
self.pulsing = False
self.pulser.pause()
if self.blinking:
self.blinking = False
if self._value:
self.duty_cycle(100)
else:
self.duty_cycle(0)
return True
示例14: serve_forever
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def serve_forever(self):
# we could join on the threads, but join blocks all interrupts (including
# ctrl+c, so just spin here
# noinspection PyBroadException
try:
def sig_manager(sig, callstack):
self.stop()
self._log.info('*** signal %d received.' % sig)
return signal.SIG_IGN
prev_handler = signal.signal(signal.SIGINT, sig_manager)
except Exception:
# signal.pause() is missing for Windows; wait 1ms and loop instead
pass
except KeyboardInterrupt:
pass
while self._alive:
try:
time.sleep(1)
except Exception:
self._alive = False
self._log.debug(' ** serve_forever() quitting')
示例15: pause_for_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import pause [as 别名]
def pause_for_signal():
"""
Pauses the current thread in a way that can still receive signals like SIGINT from Ctrl+C.
Implementation notes:
- Linux uses signal.pause()
- Windows uses a loop that sleeps for 1 ms at a time, allowing signals
to interrupt the thread fairly quickly.
:return: None
:rtype: None
"""
try:
while True:
signal.pause()
except AttributeError:
# signal.pause() is missing for Windows; wait 1ms and loop instead
while True:
time.sleep(0.001)