我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用psutil.STATUS_RUNNING。
def test_status(self): p = psutil.Process() self.assertEqual(p.status(), psutil.STATUS_RUNNING)
def check_current_running_experiments(expdb): sql = "SELECT *, NOW() - starttime AS time_elapsed " \ "FROM exp " \ "WHERE status = 'running' " \ "ORDER BY starttime, id " exps = [] for exp in list(expdb.sql_query(sql)): if exp.pid is not None: # Just check if process is still alive try: # print "Checking pid = {}".format(exp.pid) # os.kill(exp.pid, 0) proc = psutil.Process(exp.pid) except psutil.NoSuchProcess: # print "pid is dead" if exp.manager_uuid != manager_uuid: set_experiment_as_error(expdb, exp, "daemon crashed") else: raise Exception else: if proc.status() == psutil.STATUS_ZOMBIE: set_experiment_as_error(expdb, exp, "zombie") elif proc.status() == psutil.STATUS_RUNNING: # print "pid is alive and running" exps.append(exp) else: raise Exception("Process (pid={}) status `{}' not supported.".format(exp.pid, proc.status())) else: set_experiment_as_error(expdb, exp, "no pid") return exps