本文整理汇总了Python中signal.SIGTSTP属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGTSTP属性的具体用法?Python signal.SIGTSTP怎么用?Python signal.SIGTSTP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIGTSTP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pause_children
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [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
示例2: save
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def save(self):
"""Save important things to file"""
self.flag.value = 2
logger.info("Saving")
# Ignore sigtstp messages from now on:
signal.signal(signal.SIGTSTP, self.signal_ignore)
# Saving only happens on the first CPU
p = psutil.Process()
current_cpus = p.cpu_affinity()
if len(current_cpus) > 1:
p.cpu_affinity([current_cpus[0]])
# Save children
self.save_children(save_timeout=300)
# Save myself
with open(self.save_file, 'wb') as pickle_file:
pickle.dump(self, pickle_file, pickle.HIGHEST_PROTOCOL)
logger.info("Completed saving")
self.flag.value = 3
示例3: ignore_user_entered_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def ignore_user_entered_signals():
"""
Ignores user entered signals to avoid process getting killed.
"""
if is_windows:
signal_list = [signal.SIGINT]
else:
signal_list = [signal.SIGINT, signal.SIGQUIT, signal.SIGTSTP]
actual_signals = []
for user_signal in signal_list:
actual_signals.append(signal.signal(user_signal, signal.SIG_IGN))
try:
yield
finally:
for sig, user_signal in enumerate(signal_list):
signal.signal(user_signal, actual_signals[sig])
示例4: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def __init__(self, name, pid_dir='/var/run', signals=None):
"""
Constructor.
``name`` is a string that identifies the daemon. The name is
used for the name of the daemon process, the PID file and for
the messages to syslog.
``pid_dir`` is the directory in which the PID file is stored.
``signals`` list of operating signals, that should be available
for use with :py:meth:`.send_signal`, :py:meth:`.got_signal`,
:py:meth:`.wait_for_signal`, and :py:meth:`.check_signal`. Note
that SIGTERM is always supported, and that SIGTTIN, SIGTTOU, and
SIGTSTP are never supported.
"""
self.name = name
self.pid_file = _PIDFile(os.path.join(pid_dir, name + '.pid'))
self._signal_events = {int(s): threading.Event()
for s in ((signals or []) + [signal.SIGTERM])}
self.logger = logging.getLogger(name)
if not self.logger.handlers:
self.logger.addHandler(logging.NullHandler())
self.files_preserve = []
示例5: _cleanup_worker
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def _cleanup_worker(self, signum, frame):
"""Handle cleanup when the process is sent a signal.
This will handle releasing tasks in flight and deleting tasks that have
been completed.
"""
logger.info('Process sent signal %d. Cleaning up tasks...' % signum)
num_completed, num_incomplete = self._release_batch()
# When the process is suspended we release tasks and then return to the
# main loop.
if signum == signal.SIGTSTP:
self._on_sigtstp(num_completed, num_incomplete)
return
else:
# Allow the client of this library to do any setup before
# shutting down the worker.
settings.ON_WORKER_SHUTDOWN()
self._on_shutdown(num_completed, num_incomplete)
sys.exit(0)
示例6: make_default_signal_map
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def make_default_signal_map():
""" Make the default signal map for this system.
The signals available differ by system. The map will not
contain any signals not defined on the running system.
"""
name_map = {
'SIGTSTP': None,
'SIGTTIN': None,
'SIGTTOU': None,
'SIGTERM': 'terminate',
}
signal_map = dict(
(getattr(signal, name), target)
for (name, target) in name_map.items()
if hasattr(signal, name))
return signal_map
示例7: make_default_signal_map
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def make_default_signal_map():
""" Make the default signal map for this system.
The signals available differ by system. The map will not
contain any signals not defined on the running system.
"""
name_map = {
'SIGTSTP': None,
'SIGTTIN': None,
'SIGTTOU': None,
'SIGTERM': 'terminate',
}
signal_map = dict(
(getattr(signal, name), target)
for (name, target) in name_map.items()
if hasattr(signal, name))
return signal_map
示例8: __enter__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def __enter__(self):
# Make sure to cleanup GPIO afterward
if not self.__signals_trapped:
self.__signals_trapped = True
for sig in [signal.SIGQUIT, signal.SIGTERM, signal.SIGTSTP]:
if hasattr(signal.getsignal(sig), '__call__'):
deleg = signal.getsignal(sig)
def delegate(signum, stack):
self.__exit__(None, None, None)
deleg(signum, stack)
signal.signal(sig, delegate)
else:
def delegate(signum, stack):
self.__exit__(None, None, None)
signal.signal(sig, delegate)
return self
示例9: suspend_to_background
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def suspend_to_background(self, suspend_group=True):
"""
(Not thread safe -- to be called from inside the key bindings.)
Suspend process.
:param suspend_group: When true, suspend the whole process group.
(This is the default, and probably what you want.)
"""
# Only suspend when the opperating system supports it.
# (Not on Windows.)
if hasattr(signal, 'SIGTSTP'):
def run():
# Send `SIGSTP` to own process.
# This will cause it to suspend.
# Usually we want the whole process group to be suspended. This
# handles the case when input is piped from another process.
if suspend_group:
os.kill(0, signal.SIGTSTP)
else:
os.kill(os.getpid(), signal.SIGTSTP)
self.run_in_terminal(run)
示例10: test_default_rewrites_can_be_overriden_with_setsid_enabled
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def test_default_rewrites_can_be_overriden_with_setsid_enabled():
"""In setsid mode, dumb-init should allow overwriting the default
rewrites (but still suspend itself).
"""
rewrite_map = {
signal.SIGTTIN: signal.SIGTERM,
signal.SIGTTOU: signal.SIGINT,
signal.SIGTSTP: signal.SIGHUP,
}
with print_signals(_rewrite_map_to_args(rewrite_map)) as (proc, _):
for send, expect_receive in rewrite_map.items():
assert process_state(proc.pid) in ['running', 'sleeping']
proc.send_signal(send)
assert proc.stdout.readline() == '{}\n'.format(expect_receive).encode('ascii')
os.waitpid(proc.pid, os.WUNTRACED)
assert process_state(proc.pid) == 'stopped'
proc.send_signal(signal.SIGCONT)
assert proc.stdout.readline() == '{}\n'.format(signal.SIGCONT).encode('ascii')
assert process_state(proc.pid) in ['running', 'sleeping']
示例11: _catch_interrupt
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def _catch_interrupt(signal_no, frame):
"""
SIGINT handler. We ignore the signal and frame info passed in.
"""
# Stop pep-8 shouting at me for unused params I can't control.
del frame
# The OS already caught the ctrl-c, so inject it now for the next
# input.
if signal_no == signal.SIGINT:
curses.ungetch(3)
elif signal_no == signal.SIGTSTP:
curses.ungetch(26)
示例12: test_catch_exceptions
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def test_catch_exceptions(self):
"""
Check that we can catch exceptions (e.g. for ctrl-c).
"""
def internal_checks(screen):
# Not much we can do here as refresh will draw to a screen we can't
# query. Check that we don't hit an Exception on refresh().
if sys.platform == "win32":
# Strictly speaking, this doesn't test catching ctrl-c as
# it isn't possible to trigger the control handler (even if
# we don't catch interrupts). Still a good basic check for
# input, though.
event = win32console.PyINPUT_RECORDType(win32console.KEY_EVENT)
event.Char = u"\03"
event.KeyDown = 1
event.RepeatCount = 1
event.ControlKeyState = win32con.LEFT_CTRL_PRESSED
event.VirtualKeyCode = 67
event.VirtualScanCode = 46
screen._stdin.WriteConsoleInput([event])
event.KeyDown = 0
screen._stdin.WriteConsoleInput([event])
ch = screen.get_event()
self.assertEqual(ch.key_code, 3)
self.assertIsNone(screen.get_event())
else:
# Check Ctrl-c (and no other input)
os.kill(os.getpid(), signal.SIGINT)
ch = screen.get_event()
self.assertEqual(ch.key_code, 3)
self.assertIsNone(screen.get_event())
# Check Ctrl-z (and no other input)
os.kill(os.getpid(), signal.SIGTSTP)
ch = screen.get_event()
self.assertEqual(ch.key_code, 26)
self.assertIsNone(screen.get_event())
Screen.wrapper(internal_checks, height=15, catch_interrupt=True)
示例13: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def __init__(self, app):
super(Console, self).__init__(app)
self.interrupt = Event()
gevent.signal(signal.SIGTSTP, self.interrupt.set)
self.console_locals = []
示例14: handleInput
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def handleInput(self, char):
#log.msg('handling %s' % repr(char))
if char in ('\n', '\r'):
self.escapeMode = 1
self.write(char)
elif self.escapeMode == 1 and char == options['escape']:
self.escapeMode = 2
elif self.escapeMode == 2:
self.escapeMode = 1 # so we can chain escapes together
if char == '.': # disconnect
log.msg('disconnecting from escape')
stopConnection()
return
elif char == '\x1a': # ^Z, suspend
def _():
_leaveRawMode()
sys.stdout.flush()
sys.stdin.flush()
os.kill(os.getpid(), signal.SIGTSTP)
_enterRawMode()
reactor.callLater(0, _)
return
elif char == 'R': # rekey connection
log.msg('rekeying connection')
self.conn.transport.sendKexInit()
return
elif char == '#': # display connections
self.stdio.write('\r\nThe following connections are open:\r\n')
channels = self.conn.channels.keys()
channels.sort()
for channelId in channels:
self.stdio.write(' #%i %s\r\n' % (channelId, str(self.conn.channels[channelId])))
return
self.write('~' + char)
else:
self.escapeMode = 0
self.write(char)
示例15: _catch_interrupt
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def _catch_interrupt(signal_no, frame):
"""
SIGINT handler. We ignore the signal and frame info passed in.
"""
# Stop pep-8 shouting at me for unused params I can't control.
del frame
# The OS already caught the ctrl-c, so inject it now for the next
# input.
if signal_no == signal.SIGINT:
curses.ungetch(3)
elif signal_no == signal.SIGTSTP:
curses.ungetch(26)
return