本文整理匯總了Python中signal.SIGKILL屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.SIGKILL屬性的具體用法?Python signal.SIGKILL怎麽用?Python signal.SIGKILL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類signal
的用法示例。
在下文中一共展示了signal.SIGKILL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: after_scenario
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def after_scenario(context, scenario):
"""Cleans up after each scenario completes."""
if hasattr(context, "cli") and context.cli and not context.exit_sent:
# Quit nicely.
if not context.atprompt:
dbname = context.currentdb
context.cli.expect_exact("{0}> ".format(dbname), timeout=15)
context.cli.sendcontrol("c")
context.cli.sendcontrol("d")
try:
context.cli.expect_exact(pexpect.EOF, timeout=15)
except pexpect.TIMEOUT:
print("--- after_scenario {}: kill cli".format(scenario.name))
context.cli.kill(signal.SIGKILL)
if hasattr(context, "tmpfile_sql_help") and context.tmpfile_sql_help:
context.tmpfile_sql_help.close()
context.tmpfile_sql_help = None
# # TODO: uncomment to debug a failure
# def after_step(context, step):
# if step.status == "failed":
# import pdb; pdb.set_trace()
示例2: stopChild
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def stopChild(self):
logging.debug("Terminate child...")
if self.p is not None:
self.p.terminate()
logging.debug("Kill server: " + str(self.serverPid))
if self.serverPid is not None:
try:
os.kill(self.serverPid, signal.SIGTERM)
os.kill(self.serverPid, signal.SIGKILL)
except Exception as e:
logging.error("Kill exception, but child should be alive: " + str(e))
self.p = None
self.serverPid = None
########################
示例3: do_GET
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def do_GET(self):
client_address = self.client_address[0]
logger.info('Serving transcoded media file to {} ...'.format(
client_address))
self.send_head()
path = self.translate_path(self.path)
command = VLCEncoderSettings.command(path)
logger.info('Launching {}'.format(command))
try:
with open(os.devnull, 'w') as dev_null:
encoder_process = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=dev_null)
shutil.copyfileobj(encoder_process.stdout, self.wfile)
except:
logger.info('Connection from {} closed.'.format(client_address))
logger.debug(traceback.format_exc())
finally:
pid = encoder_process.pid
logger.info('Terminating process {}'.format(pid))
try:
os.kill(pid, signal.SIGKILL)
except:
pass
示例4: PosixShutdown
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def PosixShutdown():
"""Kills a posix process with os.kill."""
dev_process = GlobalProcess()
children = dev_process.Children()
for term_signal in (signal.SIGTERM, signal.SIGKILL):
for child in children:
if child.process is None:
continue
if child.process.returncode is not None:
continue
pid = child.process.pid
try:
logging.debug('posix kill %d with signal %d', pid, term_signal)
os.kill(pid, term_signal)
except OSError, err:
logging.error('Error encountered sending pid %d signal %d:%s\n',
pid, term_signal, err)
break
time.sleep(0.2)
示例5: stop
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def stop(self, graceful=True):
"""\
Stop workers
:attr graceful: boolean, If True (the default) workers will be
killed gracefully (ie. trying to wait for the current connection)
"""
if self.reexec_pid == 0 and self.master_pid == 0:
for l in self.LISTENERS:
l.close()
self.LISTENERS = []
sig = signal.SIGTERM
if not graceful:
sig = signal.SIGQUIT
limit = time.time() + self.cfg.graceful_timeout
# instruct the workers to exit
self.kill_workers(sig)
# wait until the graceful timeout
while self.WORKERS and time.time() < limit:
time.sleep(0.1)
self.kill_workers(signal.SIGKILL)
示例6: murder_workers
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def murder_workers(self):
"""\
Kill unused/idle workers
"""
if not self.timeout:
return
workers = list(self.WORKERS.items())
for (pid, worker) in workers:
try:
if time.time() - worker.tmp.last_update() <= self.timeout:
continue
except (OSError, ValueError):
continue
if not worker.aborted:
self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
worker.aborted = True
self.kill_worker(pid, signal.SIGABRT)
else:
self.kill_worker(pid, signal.SIGKILL)
示例7: __init__
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def __init__(self, rr_endpoint, ann_endpoint):
super(ZMQWorker,self).__init__()
# Upstream endpoints
self.rr_endpoint = rr_endpoint
self.ann_endpoint = ann_endpoint
# Downstream endpoints
self.task_endpoint = self.make_internal_endpoint()
self.result_endpoint = self.make_internal_endpoint()
self.master_id = None
self.identified = False
# The task currently being processed
self.pending_task = None
# Executor process
self.shutdown_timeout = 5.0 # Five second wait between shutdown message and SIGINT and SIGINT and SIGKILL
self.executor_process = None
示例8: terminate_process
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def terminate_process():
if m2ee:
logging.info("stopping app...")
if not m2ee.stop():
if not m2ee.terminate():
m2ee.kill()
try:
this_process = os.getpgid(0)
logging.debug(
"Terminating process group with pgid=%s", format(this_process)
)
os.killpg(this_process, signal.SIGTERM)
time.sleep(3)
os.killpg(this_process, signal.SIGKILL)
except OSError:
logging.exception("Failed to terminate all child processes")
示例9: kill_process
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def kill_process(pid, sig=None):
"""Try to send signal to given process."""
if sig is None:
sig = signal.SIGKILL # set default lazily, otherwise importing fails on Windows
try:
os.kill(pid, sig)
except OSError as e:
if e.errno == errno.ESRCH:
# process itself returned and exited before killing
logging.debug(
"Failure %s while killing process %s with signal %s: %s",
e.errno,
pid,
sig,
e.strerror,
)
else:
logging.warning(
"Failure %s while killing process %s with signal %s: %s",
e.errno,
pid,
sig,
e.strerror,
)
示例10: do_cancel
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def do_cancel(self, sig=signal.SIGKILL):
"""
Kill process during migration.
:param sig: The signal to send
:raise: test.error when kill fails
"""
def _get_pid():
cmd = "ps aux |grep 'virsh .*migrate' |grep -v grep |awk '{print $2}'"
pid = process.run(cmd, shell=True).stdout_text
return pid
pid = utils_misc.wait_for(_get_pid, 30)
if utils_misc.safe_kill(pid, sig):
logging.info("Succeed to cancel migration: [%s].", pid.strip())
else:
raise exceptions.TestError("Fail to cancel migration: [%s]"
% pid.strip())
示例11: test_wait_timeout_0
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def test_wait_timeout_0(self):
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
self.assertRaises(psutil.TimeoutExpired, p.wait, 0)
p.kill()
stop_at = time.time() + 2
while True:
try:
code = p.wait(0)
except psutil.TimeoutExpired:
if time.time() >= stop_at:
raise
else:
break
if POSIX:
self.assertEqual(code, -signal.SIGKILL)
else:
self.assertEqual(code, signal.SIGTERM)
self.assertFalse(p.is_running())
示例12: kill_on_exception
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def kill_on_exception(logname):
"""decorator to ensure functions will kill ryu when an unhandled exception
occurs"""
def _koe(func):
@wraps(func)
def __koe(*args, **kwargs):
try:
func(*args, **kwargs)
except:
logging.getLogger(logname).exception(
"Unhandled exception, killing RYU")
logging.shutdown()
os.kill(os.getpid(), signal.SIGKILL)
return __koe
return _koe
示例13: detach
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def detach(self):
"""
Stop listening for log messages.
After this is called, no additional messages will be added to the
queue.
"""
if self.listening:
# We have to kill the process explicitly with SIGKILL,
# terminate() function does not work here.
for process in self.processes:
os.kill(process.pid, signal.SIGKILL)
self.processes = []
self.listening = False
示例14: check_kill_process
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def check_kill_process(pstring):
# Static method for killing given processes
for line in os.popen("ps ax | grep " + pstring + " | grep -v grep"):
fields = line.split()
pid = fields[0]
if pid:
os.kill(int(pid), signal.SIGKILL)
示例15: kill
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGKILL [as 別名]
def kill(self):
"""Kill the process with SIGKILL
"""
self.send_signal(signal.SIGKILL)