本文整理汇总了Python中psutil.Process.wait方法的典型用法代码示例。如果您正苦于以下问题:Python Process.wait方法的具体用法?Python Process.wait怎么用?Python Process.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Process
的用法示例。
在下文中一共展示了Process.wait方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kill_proc_tree
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import wait [as 别名]
def kill_proc_tree(pid, including_parent=True, timeout=5):
try:
parent = Process(pid)
except NoSuchProcess:
return
children = parent.children(recursive=True)
for child in children:
if verbose.kill:
print("killing {}".format(child.pid))
try:
child.kill()
child.terminate()
except NoSuchProcess:
pass
gone, still_alive = wait_procs(children, timeout=timeout)
if including_parent:
try:
if verbose.kill:
print("killing {}".format(parent.pid))
parent.kill()
parent.terminate()
try:
parent.wait(timeout)
except TimeoutExpired:
print("timeout expired, process may still be around: {}".format(parent.pid))
except NoSuchProcess:
pass
示例2: wait_output
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import wait [as 别名]
def wait_output(settings, popen):
"""Returns `True` if we can get output of the command in the
`wait_command` time.
Command will be killed if it wasn't finished in the time.
"""
proc = Process(popen.pid)
try:
proc.wait(settings.wait_command)
return True
except TimeoutExpired:
for child in proc.get_children(recursive=True):
child.kill()
proc.kill()
return False
示例3: _kill
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import wait [as 别名]
def _kill(pid, timeout=1.5):
try:
process = Process(pid)
except NoSuchProcess:
return
try:
process.send_signal(SIGINT)
sleep(timeout)
except OSError:
pass
finally:
try:
process.send_signal(SIGKILL)
except (OSError, NoSuchProcess):
pass
process.wait()
示例4: _wait_output
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import wait [as 别名]
def _wait_output(popen, is_slow):
"""Returns `True` if we can get output of the command in the
`settings.wait_command` time.
Command will be killed if it wasn't finished in the time.
:type popen: Popen
:rtype: bool
"""
proc = Process(popen.pid)
try:
proc.wait(settings.wait_slow_command if is_slow
else settings.wait_command)
return True
except TimeoutExpired:
for child in proc.children(recursive=True):
child.kill()
proc.kill()
return False
示例5: stop_diamond
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import wait [as 别名]
def stop_diamond(conf_path):
config_file = os.path.join(conf_path, CONFIG_NAME)
pid = get_pid(config_file)
if pid:
need_kill = True
try:
diamond_process = Process(pid)
diamond_process.terminate()
diamond_process.wait(timeout=DEFAULT_TIMEOUT)
need_kill = diamond_process.is_running()
except Error:
pass
if need_kill:
call(["sudo", "kill", str(pid)])
# diamond deletes the pid file, even if killed
for _ in range(DEFAULT_TIMEOUT):
pid = get_pid(config_file)
if not pid:
return
sleep(1)
else:
raise exceptions.NonRecoverableError('Failed reading diamond pid file')
示例6: stop
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import wait [as 别名]
def stop(self):
"""
Stop the Elasticsearch server.
:rtype : ElasticsearchRunner
:return: The instance called on.
"""
if self.is_running():
server_proc = Process(self.es_state.server_pid)
server_proc.terminate()
server_proc.wait()
if process_exists(self.es_state.server_pid):
logging.warn('Failed to stop Elasticsearch server process PID %d ...' % self.es_state.server_pid)
# delete transient directories
if 'path' in self.es_config:
if 'log' in self.es_config['path']:
log_path = self.es_config['path']['log']
logging.info('Removing transient log path %s ...' % log_path)
rmtree(log_path)
if 'data' in self.es_config['path']:
data_path = self.es_config['path']['data']
logging.info('Removing transient data path %s ...' % data_path)
rmtree(data_path)
# delete temporary config file
if os.path.exists(self.es_state.config_fn):
logging.info('Removing transient configuration file %s ...' % self.es_state.config_fn)
os.remove(self.es_state.config_fn)
self.es_state = None
self.es_config = None
else:
logging.warn('Elasticsearch is not running ...')
return self