本文整理汇总了Python中signal.pause函数的典型用法代码示例。如果您正苦于以下问题:Python pause函数的具体用法?Python pause怎么用?Python pause使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pause函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
port = common.PORT
username = input("Choose a username : ")
dark_vader, luke = Pipe()
p = Process(target=server_process, args=(luke, port, username))
p.start()
def pause_handler(signum, frame):
pass
def chat_handler(signum, frame):
print(u'\033[2K\n\033[1A',end='', flush=True)
print(dark_vader.recv())
print('{} > '.format(username), end="", flush=True)
signal.signal(41, pause_handler)
signal.signal(42, chat_handler)
signal.pause()
chat.chat(port, username)
p.terminate()
示例2: reap
def reap(self):
"""Collect the dead jobs."""
while self._running:
dead = set()
for job in self._running:
st = job.state(self._cache)
if st == _RUNNING: continue
if st == _FAILURE or st == _KILLED:
self._failures += 1
if self._stop_on_failure:
self._cancelled = True
for job in self._running:
job.kill()
dead.add(job)
break
for job in dead:
self._completed += 1
self._running.remove(job)
if dead: return
if (not self._travis):
message('WAITING', '%d jobs running, %d complete, %d failed' % (
len(self._running), self._completed, self._failures))
if platform.system() == 'Windows':
time.sleep(0.1)
else:
global have_alarm
if not have_alarm:
have_alarm = True
signal.alarm(10)
signal.pause()
示例3: main
def main():
god = God(paper=PAPER)
god.setup()
god.start()
signal.pause()
god.world()
示例4: test_signals
def test_signals(self):
# Test signal handling semantics of threads.
# We spawn a thread, have the thread send two signals, and
# wait for it to finish. Check that we got both signals
# and that they were run by the main thread.
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()
示例5: test_sigchld
def test_sigchld():
r = reaper.Reaper()
old_sigchld = signal.getsignal(signal.SIGCHLD)
r.hookup_sigchld()
assert r.old_sigchld is old_sigchld
assert signal.getsignal(signal.SIGCHLD) == reaper.theReaper.handle_sigchld
del r
waiting = [DelayedExitFork(i, (i % 32) / 32) for i in range(256)]
while waiting:
signal.pause()
i = 0
while i < len(waiting):
if waiting[i].obit is not None:
f = waiting.pop(i)
assert f.obit.pid == f.pid
assert f.obit.exitstatus == f.expectedstatus
assert f.obit.termsig is None
assert f.obit.stopsig is None
assert f.obit.coredump is False
else:
i += 1
reaper.theReaper.unhookup_sigchld()
assert signal.getsignal(signal.SIGCHLD) is old_sigchld
reaper.theReaper = None
示例6: withEmpty
def withEmpty(words):
start = time.time()
for w in words:
pass
print '%fs' % (time.time() - start)
signal.pause()
示例7: main
def main(self):
# See comment at top of file about zuul imports
import zuul.scheduler
import zuul.launcher.jenkins
import zuul.trigger.gerrit
self.sched = zuul.scheduler.Scheduler()
jenkins = zuul.launcher.jenkins.Jenkins(self.config, self.sched)
gerrit = zuul.trigger.gerrit.Gerrit(self.config, self.sched)
self.sched.setLauncher(jenkins)
self.sched.setTrigger(gerrit)
self.sched.start()
self.sched.reconfigure(self.config)
self.sched.resume()
signal.signal(signal.SIGHUP, self.reconfigure_handler)
signal.signal(signal.SIGUSR1, self.exit_handler)
while True:
try:
signal.pause()
except KeyboardInterrupt:
print "Ctrl + C: asking scheduler to exit nicely...\n"
self.exit_handler(signal.SIGINT, None)
示例8: main
def main():
syncilainen = None
def reload(signum, stack):
if syncilainen:
syncilainen.reload_config()
def quit(signum, stack):
if syncilainen:
syncilainen.stop()
exit(0)
# listen for SIGHUP or SIGUSR1 and reload config
signal.signal(signal.SIGHUP, reload)
signal.signal(signal.SIGUSR1, reload)
# listen for SIGINT and quit gracefully
signal.signal(signal.SIGINT, quit)
# boilerplate
options = read_options()
setup_logging(options.log_file, options.debug)
logging.info("PID: %s" % os.getpid())
# start the syncilainen daemon
syncilainen = Syncilainen()
syncilainen.start()
# wait for signals
while True:
signal.pause()
示例9: main
def main(self):
self.setup_logging()
self.pool = nodepool.nodepool.NodePool(self.args.secure,
self.args.config,
self.args.no_deletes,
self.args.no_launches,
self.args.no_images)
if self.args.builder:
self.builder = nodepool.builder.NodePoolBuilder(
self.args.config, self.args.build_workers,
self.args.upload_workers)
if not self.args.no_webapp:
self.webapp = nodepool.webapp.WebApp(self.pool)
signal.signal(signal.SIGINT, self.exit_handler)
# For back compatibility:
signal.signal(signal.SIGUSR1, self.exit_handler)
signal.signal(signal.SIGUSR2, stack_dump_handler)
signal.signal(signal.SIGTERM, self.term_handler)
self.pool.start()
if self.args.builder:
nb_thread = threading.Thread(target=self.builder.runForever)
nb_thread.start()
if not self.args.no_webapp:
self.webapp.start()
while True:
signal.pause()
示例10: serve_forever
def serve_forever(host, port, childnum):
# create, bind, listen
listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# re-use the port
listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_sock.bind((host, port))
listen_sock.listen(BACKLOG)
print 'Listening on port %d ...' % port
global MAP
MAP = create_array(childnum)
# prefork children
global PIDS
PIDS = [create_child(index, listen_sock) for index in range(childnum)]
# setup SIGTERM handler - in case the parent is killed
signal.signal(signal.SIGTERM, _cleanup)
# parent never calls 'accept' - children do all the work
# all parent does is sleeping :)
try:
signal.pause()
except KeyboardInterrupt:
_exit_handler()
print_stats()
示例11: stop
def stop(self):
"""Shutdown the MCP and child processes cleanly"""
LOGGER.info('Shutting down controller')
self.set_state(self.STATE_STOP_REQUESTED)
# Clear out the timer
signal.setitimer(signal.ITIMER_PROF, 0, 0)
self._mcp.stop_processes()
if self._mcp.is_running:
LOGGER.info('Waiting up to 3 seconds for MCP to shut things down')
signal.setitimer(signal.ITIMER_REAL, 3, 0)
signal.pause()
LOGGER.info('Post pause')
# Force MCP to stop
if self._mcp.is_running:
LOGGER.warning('MCP is taking too long, requesting process kills')
self._mcp.stop_processes()
del self._mcp
else:
LOGGER.info('MCP exited cleanly')
# Change our state
self._stopped()
LOGGER.info('Shutdown complete')
示例12: start
def start(self):
# Watch the source files for changes
filewatch = Observer()
filewatch.schedule(FilewatchHandler(parent=self,
ignore_patterns=['*.swp', '*~']),
self.src_dir,
recursive=True)
# Clean shutdown on ctrl+c
def signal_handler(signal, frame):
print
print 'Shutting down...'
self.stop_server()
filewatch.stop()
signal.signal(signal.SIGINT, signal_handler)
self.rebuild()
self.start_server()
print 'Serving at port', self.port
print 'Serving files from', self.final_build_dir
print('Press Ctrl+C to stop')
filewatch.start()
signal.pause()
filewatch.join(5000)
示例13: main
def main():
threads=[]
t = threading.Thread(
target=sniff,
kwargs={'prn':arp_handler, 'filter':'arp', 'iface': iface_name, 'store': 0},
name='ARP'
)
threads.append(t)
t = threading.Thread(
target=sniff,
kwargs={'prn':icmp_handler, 'filter':'icmp', 'iface': iface_name, 'store': 0},
name='ICMP'
)
threads.append(t)
for worker in threads:
worker.daemon=True
print "%s worker starting" % (worker.name)
worker.start()
try:
while (42):
time.sleep(1)
signal.pause()
except KeyboardInterrupt:
print "CTRL+C caught"
for worker in threads:
print "%s worker joining main thread" % (worker.name)
worker.join(1)
sys.exit(0)
示例14: reap
def reap(self):
"""Collect the dead jobs."""
while self._running:
dead = set()
for job in self._running:
st = job.state(self._cache)
if st == _RUNNING:
continue
if st == _FAILURE:
self._failures += 1
if st == _KILLED:
self._failures += 1
dead.add(job)
for job in dead:
self._completed += 1
self._running.remove(job)
if dead:
return
if not self._travis:
message(
"WAITING",
"%d jobs running, %d complete, %d failed" % (len(self._running), self._completed, self._failures),
)
global have_alarm
if not have_alarm:
have_alarm = True
signal.alarm(10)
signal.pause()
示例15: main
def main():
processes = {}
create_ugc_directories()
def restart(*args, **kwargs):
for app, proc in processes.items():
if proc:
print 'killing %s (%s)...' % (app, proc.pid)
proc.terminate()
proc.communicate()
if 'sass' in run('which sass', stdout=subprocess.PIPE).stdout.read():
sass()
redis()
memcache()
nginx()
for app in processes.keys():
processes[app] = globals()[app]()
print '%s: %s' % (app, processes[app].pid if processes[app] else None)
print 'All systems go! Ctrl+C to restart everything, Ctrl+Z to end.\n'
restart()
signal.signal(signal.SIGINT, restart)
while True:
signal.pause()