python类STATUS_ZOMBIE的实例源码

refresh_manager.py 文件源码 项目:data_pipeline 作者: Yelp 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def set_zombie_refresh_to_fail(self, refresh_job):
        current_pid = refresh_job.pid
        if current_pid is None:
            return

        p = psutil.Process(current_pid)
        if p.status() != psutil.STATUS_ZOMBIE:
            return

        refresh = self.schematizer.get_refresh_by_id(
            refresh_job.refresh_id
        )
        if refresh.status == RefreshStatus.IN_PROGRESS:
            # Must update manually (not relying on the signal),
            # as the process may not properly handle the signal
            # if it's a zombie
            self.schematizer.update_refresh(
                refresh_id=refresh_job.refresh_id,
                status=RefreshStatus.FAILED,
                offset=0
            )
            source = refresh_job.source
            del self.active_refresh_jobs[source]
        os.kill(current_pid, signal.SIGINT)
worker.py 文件源码 项目:denet 作者: lachlants 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def wait(self, dt = 0.001):
        count = 0
        done = False
        while(not done):
            with self.active.get_lock():
                if self.active.value == 0:
                    done=True

            #check for exceptions
            try:
                error = self.error_q.get(block=False)
                self.proc.terminate()
                raise(error)
                exit(1)
            except queue.Empty:
                pass

            #check if process has stopped
            # if self.ps_proc.status() == psutil.STATUS_ZOMBIE or self.ps_proc.status() == psutil.STATUS_DEAD:
            #     raise Exception("Worker died prematurely: " + self.gpu)

            time.sleep(dt)
            count += 1

        return count*dt
schedlocal.py 文件源码 项目:pypers 作者: frankosan 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def status(self,job_ids):

        """  Returns the status of a pid from a local background 'job'
        """

        job_ids = set(job_ids)
        status_map = dict.fromkeys(job_ids,'Unknown')

        for job_id in job_ids:
            job_failed_file = os.path.join(self.job_ids.get(job_id, {}).get('cwd'), FAILED_FILE)
            if not psutil.pid_exists(int(job_id)):
                if os.path.exists(job_failed_file):
                    status_map[job_id] = JOB_STATUS.FAILED
                else:
                    status_map[job_id] = JOB_STATUS.SUCCEEDED
            elif psutil.Process(job_id).status() == psutil.STATUS_ZOMBIE:
                if os.path.exists(job_failed_file):
                    status_map[job_id] = JOB_STATUS.FAILED
                else:
                    status_map[job_id] = JOB_STATUS.SUCCEEDED
            else:
                status_map[job_id] = JOB_STATUS.RUNNING

        return status_map
processmanager.py 文件源码 项目:social-listener 作者: topix-hackademy 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def refresh_status(self):
        """
        Refresh process status.
        If a process is dead or in zombie status a flag 'is_alive' will be setted to False
        :return:
        """
        what_time_is_now = what_time_is_it()
        for process in Connection.Instance().db.manager.find({"is_alive": True}):
            if (not psutil.pid_exists(process['pid'])) or \
                    (psutil.pid_exists(process['pid']) and psutil.Process(process['pid']).status() ==
                        psutil.STATUS_ZOMBIE):
                self.update_process(process['pid'], {
                        'is_alive': False,
                        'last_update': what_time_is_now
                    })
            elif psutil.pid_exists(process['pid']):
                self.update_process(process['pid'], {'last_update': what_time_is_now})
        logging.info('Refresh Done!')
test_freeze_update_available.py 文件源码 项目:pyupdater-wx-demo 作者: wettenhj 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def PidIsRunning(pid):
    """
    Check if a process with PID pid is running.
    """
    try:
        proc = psutil.Process(int(pid))
        if proc.status == psutil.STATUS_DEAD:
            return False
        if proc.status == psutil.STATUS_ZOMBIE:
            return False
        return True  # Assume other status are valid
    except psutil.NoSuchProcess:
        return False
test_process.py 文件源码 项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def create_time(self, ret, proc):
        try:
            self.assertGreaterEqual(ret, 0)
        except AssertionError:
            if OPENBSD and proc.status == psutil.STATUS_ZOMBIE:
                pass
            else:
                raise
        # this can't be taken for granted on all platforms
        # self.assertGreaterEqual(ret, psutil.boot_time())
        # make sure returned value can be pretty printed
        # with strftime
        time.strftime("%Y %m %d %H:%M:%S", time.localtime(ret))
test_process.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create_time(self, ret, proc):
        try:
            self.assertGreaterEqual(ret, 0)
        except AssertionError:
            if OPENBSD and proc.status == psutil.STATUS_ZOMBIE:
                pass
            else:
                raise
        # this can't be taken for granted on all platforms
        # self.assertGreaterEqual(ret, psutil.boot_time())
        # make sure returned value can be pretty printed
        # with strftime
        time.strftime("%Y %m %d %H:%M:%S", time.localtime(ret))
test_process.py 文件源码 项目:FancyWord 作者: EastonLee 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def create_time(self, ret, proc):
        try:
            self.assertGreaterEqual(ret, 0)
        except AssertionError:
            if OPENBSD and proc.status == psutil.STATUS_ZOMBIE:
                pass
            else:
                raise
        # this can't be taken for granted on all platforms
        # self.assertGreaterEqual(ret, psutil.boot_time())
        # make sure returned value can be pretty printed
        # with strftime
        time.strftime("%Y %m %d %H:%M:%S", time.localtime(ret))
pb_daemon.py 文件源码 项目:Scalable-PaQL-Queries 作者: mattfeel 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
_tensorboard.py 文件源码 项目:pydatalab 作者: googledatalab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def list():
    """List running TensorBoard instances."""

    running_list = []
    parser = argparse.ArgumentParser()
    parser.add_argument('--logdir')
    parser.add_argument('--port')
    for p in psutil.process_iter():
      if p.name() != 'tensorboard' or p.status() == psutil.STATUS_ZOMBIE:
        continue
      cmd_args = p.cmdline()
      del cmd_args[0:2]  # remove 'python' and 'tensorboard'
      args = parser.parse_args(cmd_args)
      running_list.append({'pid': p.pid, 'logdir': args.logdir, 'port': args.port})
    return pd.DataFrame(running_list)
test_process_executor.py 文件源码 项目:incubator-ariatosca 作者: apache 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_process_termination(self, executor, model, fs_test_holder, tmpdir):
        freeze_script_path = str(tmpdir.join('freeze_script'))
        with open(freeze_script_path, 'w+b') as f:
            f.write(
                '''import time
while True:
    time.sleep(5)
                '''
            )
        holder_path_argument = models.Argument.wrap('holder_path', fs_test_holder._path)
        script_path_argument = models.Argument.wrap('freezing_script_path',
                                                    str(tmpdir.join('freeze_script')))

        model.argument.put(holder_path_argument)
        model.argument.put(script_path_argument)
        ctx = MockContext(
            task_kwargs=dict(
                function='{0}.{1}'.format(__name__, freezing_task.__name__),
                arguments=dict(holder_path=holder_path_argument,
                               freezing_script_path=script_path_argument)),
        )

        executor.execute(ctx)

        @retrying.retry(retry_on_result=lambda r: r is False, stop_max_delay=60000, wait_fixed=500)
        def wait_for_extra_process_id():
            return fs_test_holder.get('subproc', False)

        task_pid = executor._tasks[ctx.task.id].proc.pid
        extra_process_pid = wait_for_extra_process_id()

        assert set([task_pid, extra_process_pid]).issubset(set(psutil.pids()))
        executor.terminate(ctx.task.id)

        # Give a chance to the processes to terminate
        time.sleep(2)

        # all processes should be either zombies or non existent
        pids = [task_pid, extra_process_pid]
        for pid in pids:
            if pid in psutil.pids():
                assert psutil.Process(pid).status() == psutil.STATUS_ZOMBIE
            else:
                # making the test more readable
                assert pid not in psutil.pids()


问题


面经


文章

微信
公众号

扫码关注公众号