本文整理汇总了Python中psutil.Process.is_running方法的典型用法代码示例。如果您正苦于以下问题:Python Process.is_running方法的具体用法?Python Process.is_running怎么用?Python Process.is_running使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Process
的用法示例。
在下文中一共展示了Process.is_running方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cleanup_children_on_terminate
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import is_running [as 别名]
def test_cleanup_children_on_terminate(self):
"""
Subprocesses spawned by tasks should be terminated on terminate
"""
class HangingSubprocessTask(luigi.Task):
def run(self):
python = sys.executable
check_call([python, '-c', 'while True: pass'])
task = HangingSubprocessTask()
queue = mock.Mock()
worker_id = 1
task_process = TaskProcess(task, worker_id, queue, lambda: None, lambda: None)
task_process.start()
parent = Process(task_process.pid)
while not parent.children():
# wait for child process to startup
sleep(0.01)
[child] = parent.children()
task_process.terminate()
child.wait(timeout=1.0) # wait for terminate to complete
self.assertFalse(parent.is_running())
self.assertFalse(child.is_running())
示例2: stop_diamond
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import is_running [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')
示例3: test_cleanup_children_on_terminate
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import is_running [as 别名]
def test_cleanup_children_on_terminate(self):
"""
Subprocesses spawned by tasks should be terminated on terminate
"""
task = HangingSubprocessTask()
queue = mock.Mock()
worker_id = 1
task_process = TaskProcess(task, worker_id, queue)
task_process.start()
parent = Process(task_process.pid)
while not parent.children():
# wait for child process to startup
sleep(0.01)
[child] = parent.children()
task_process.terminate()
child.wait(timeout=1.0) # wait for terminate to complete
self.assertFalse(parent.is_running())
self.assertFalse(child.is_running())