本文整理汇总了Python中signal.SIGHUP属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGHUP属性的具体用法?Python signal.SIGHUP怎么用?Python signal.SIGHUP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIGHUP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SIGHUP_tty
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def test_SIGHUP_tty(self):
# When not daemonized, SIGHUP should shut down the server.
try:
from signal import SIGHUP
except ImportError:
return self.skip('skipped (no SIGHUP) ')
# Spawn the process.
p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
p.write_conf(
extra='test_case_name: "test_SIGHUP_tty"')
p.start(imports='cherrypy.test._test_states_demo')
# Send a SIGHUP
os.kill(p.get_pid(), SIGHUP)
# This might hang if things aren't working right, but meh.
p.join()
示例2: enable_death_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def enable_death_signal(_warn=True):
"""
Set the "death signal" of the current process, so that
the current process will be cleaned with guarantee
in case the parent dies accidentally.
"""
if platform.system() != 'Linux':
return
try:
import prctl # pip install python-prctl
except ImportError:
if _warn:
log_once('"import prctl" failed! Install python-prctl so that processes can be cleaned with guarantee.',
'warn')
return
else:
assert hasattr(prctl, 'set_pdeathsig'), \
"prctl.set_pdeathsig does not exist! Note that you need to install 'python-prctl' instead of 'prctl'."
# is SIGHUP a good choice?
prctl.set_pdeathsig(signal.SIGHUP)
示例3: _test_restart_service_on_sighup
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def _test_restart_service_on_sighup(self, service, workers=1):
self._start_server(callback=service, workers=workers)
os.kill(self.service_pid, signal.SIGHUP)
expected_msg = (
test_server.FAKE_START_MSG * workers +
test_server.FAKE_RESET_MSG * (workers + 1))
expected_size = len(expected_msg)
utils.wait_until_true(
lambda: (os.path.isfile(self.temp_file) and
os.stat(self.temp_file).st_size ==
expected_size),
timeout=5, sleep=0.1,
exception=RuntimeError(
"Timed out waiting for file %(filename)s to be created and "
"its size become equal to %(size)s." %
{'filename': self.temp_file,
'size': expected_size}))
with open(self.temp_file, 'rb') as f:
res = f.readline()
self.assertEqual(expected_msg, res)
示例4: test_run_forwards_sighup
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def test_run_forwards_sighup(devnull):
proc = subprocess.Popen([
sys.executable, '-m', 'covimerage', 'run',
'--no-write-data', '--no-wrap-profile',
'--profile-file', devnull.name,
sys.executable, '-c',
'import signal, sys, time; '
'signal.signal(signal.SIGHUP, lambda *args: sys.exit(89)); '
'time.sleep(2)'],
stderr=subprocess.PIPE)
time.sleep(1)
proc.send_signal(signal.SIGHUP)
_, stderr = proc.communicate()
exit_code = proc.returncode
stderr = stderr.decode()
assert 'Command exited non-zero: 89' in stderr
assert exit_code == 89
示例5: initialize_signal_handlers
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def initialize_signal_handlers(self):
def handle_sighup(signum, frame):
logging.info("received SIGHUP")
self.sighup_received = True
def handle_sigterm(signal, frame):
logging.info("received SIGTERM")
self.sigterm_received = True
def handle_sigint(signal, frame):
logging.info("received SIGINT")
self.sigint_received = True
signal.signal(signal.SIGTERM, handle_sigterm)
signal.signal(signal.SIGHUP, handle_sighup)
signal.signal(signal.SIGINT, handle_sigint)
示例6: hm_health_check
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def hm_health_check(exit_event):
hm = health_manager.HealthManager(exit_event)
signal.signal(signal.SIGHUP, _mutate_config)
@periodics.periodic(CONF.health_manager.health_check_interval,
run_immediately=True)
def periodic_health_check():
hm.health_check()
health_check = periodics.PeriodicWorker(
[(periodic_health_check, None, None)],
schedule_strategy='aligned_last_finished')
def hm_exit(*args, **kwargs):
health_check.stop()
hm.executor.shutdown()
signal.signal(signal.SIGINT, hm_exit)
LOG.debug("Pausing before starting health check")
exit_event.wait(CONF.health_manager.heartbeat_timeout)
health_check.start()
示例7: _process_wrapper
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def _process_wrapper(exit_event, proc_name, function, agent_name=None):
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGHUP, _mutate_config)
if agent_name:
process_title = 'octavia-driver-agent - {} -- {}'.format(
proc_name, agent_name)
else:
process_title = 'octavia-driver-agent - {}'.format(proc_name)
setproctitle.setproctitle(process_title)
while not exit_event.is_set():
try:
function(exit_event)
except Exception as e:
if agent_name:
LOG.exception('Provider agent "%s" raised exception: %s. '
'Restarting the "%s" provider agent.',
agent_name, str(e), agent_name)
else:
LOG.exception('%s raised exception: %s. '
'Restarting %s.',
proc_name, str(e), proc_name)
time.sleep(1)
continue
break
示例8: close
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def close (self, force=True): # File-like object.
"""This closes the connection with the child application. Note that
calling close() more than once is valid. This emulates standard Python
behavior with files. Set force to True if you want to make sure that
the child is terminated (SIGKILL is sent if the child ignores SIGHUP
and SIGINT). """
if not self.closed:
self.flush()
os.close (self.child_fd)
time.sleep(self.delayafterclose) # Give kernel time to update process status.
if self.isalive():
if not self.terminate(force):
raise ExceptionPexpect ('close() could not terminate the child using terminate()')
self.child_fd = -1
self.closed = True
#self.pid = None
示例9: test_sighup
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def test_sighup(self):
self.assert_everything_has_started()
os.kill(self.subp.pid, signal.SIGHUP)
time.sleep(0.5)
lines = sorted(self.get_lines(6))
lines = self.hide_pids(lines)
self.assertEqual([
b'DEBUG:cotyledon._service:Run service light(0) [XXXX]',
b'ERROR:cotyledon.tests.examples:heavy reload',
b'ERROR:cotyledon.tests.examples:heavy reload',
b'ERROR:cotyledon.tests.examples:master reload hook',
b'INFO:cotyledon._service:Caught SIGTERM signal, '
b'graceful exiting of service light(0) [XXXX]',
b'INFO:cotyledon._service_manager:Child XXXX exited with status 0'
], lines)
os.kill(self.subp.pid, signal.SIGINT)
time.sleep(0.5)
self.assert_everything_is_dead(1)
示例10: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def __init__(self):
# Setup signal fd, this allows signal to behave correctly
if os.name == 'posix':
self.signal_pipe_r, self.signal_pipe_w = os.pipe()
self._set_nonblock(self.signal_pipe_r)
self._set_nonblock(self.signal_pipe_w)
signal.set_wakeup_fd(self.signal_pipe_w)
self._signals_received = collections.deque()
signal.signal(signal.SIGINT, signal.SIG_DFL)
if os.name == 'posix':
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
signal.signal(signal.SIGTERM, self._signal_catcher)
signal.signal(signal.SIGALRM, self._signal_catcher)
signal.signal(signal.SIGHUP, self._signal_catcher)
else:
# currently a noop on window...
signal.signal(signal.SIGTERM, self._signal_catcher)
# FIXME(sileht): should allow to catch signal CTRL_BREAK_EVENT,
# but we to create the child process with CREATE_NEW_PROCESS_GROUP
# to make this work, so current this is a noop for later fix
signal.signal(signal.SIGBREAK, self._signal_catcher)
示例11: close
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def close(self, force=True):
'''This closes the connection with the child application. Note that
calling close() more than once is valid. This emulates standard Python
behavior with files. Set force to True if you want to make sure that
the child is terminated (SIGKILL is sent if the child ignores SIGHUP
and SIGINT). '''
if not self.closed:
self.flush()
self.fileobj.close() # Closes the file descriptor
# Give kernel time to update process status.
time.sleep(self.delayafterclose)
if self.isalive():
if not self.terminate(force):
raise PtyProcessError('Could not terminate the child.')
self.fd = -1
self.closed = True
#self.pid = None
示例12: reload
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def reload():
"""
Sends a SIGHUP to the running daemon to tell it to reload all modules.
"""
log.info('reloading server.')
try:
pid = read_pid()
except Exception as e:
log.critical('could not read PID file: %s' % e)
return
try:
os.kill(pid, signal.SIGHUP)
except Exception as e:
log.critical('could not reload server: %s' % e)
示例13: register_signal_handlers
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def register_signal_handlers(callback):
# When using plain signal.signal to install a signal handler, the GUI will not shutdown until it receives the
# focus again. The following logic (inspired from https://stackoverflow.com/a/26457317) fixes this
def install_glib_handler(sig):
unix_signal_add = None
if hasattr(GLib, "unix_signal_add"):
unix_signal_add = GLib.unix_signal_add
elif hasattr(GLib, "unix_signal_add_full"):
unix_signal_add = GLib.unix_signal_add_full
if unix_signal_add:
unix_signal_add(GLib.PRIORITY_HIGH, sig, callback, sig)
def idle_handler(*args):
GLib.idle_add(callback, *args, priority=GLib.PRIORITY_HIGH)
for signal_code in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]:
signal.signal(signal_code, idle_handler)
GLib.idle_add(install_glib_handler, signal_code, priority=GLib.PRIORITY_HIGH)
示例14: test_send_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def test_send_signal(self):
code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
args = [sys.executable, '-c', code]
create = asyncio.create_subprocess_exec(*args,
stdout=subprocess.PIPE,
loop=self.loop)
proc = self.loop.run_until_complete(create)
@asyncio.coroutine
def send_signal(proc):
# basic synchronization to wait until the program is sleeping
line = yield from proc.stdout.readline()
self.assertEqual(line, b'sleeping\n')
proc.send_signal(signal.SIGHUP)
returncode = (yield from proc.wait())
return returncode
returncode = self.loop.run_until_complete(send_signal(proc))
self.assertEqual(-signal.SIGHUP, returncode)
示例15: _signal_handling
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGHUP [as 别名]
def _signal_handling(logger: logging.Logger, client: naz.Client) -> None:
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop()
try:
for _signal in [signal.SIGHUP, signal.SIGQUIT, signal.SIGTERM]:
loop.add_signal_handler(
_signal,
functools.partial(
asyncio.ensure_future,
_handle_termination_signal(logger=logger, _signal=_signal, client=client),
),
)
except ValueError as e:
logger.log(
logging.DEBUG,
{
"event": "naz.cli.signals",
"stage": "end",
"state": "this OS does not support the said signal",
"error": str(e),
},
)