當前位置: 首頁>>代碼示例>>Python>>正文


Python psutil.ZombieProcess方法代碼示例

本文整理匯總了Python中psutil.ZombieProcess方法的典型用法代碼示例。如果您正苦於以下問題:Python psutil.ZombieProcess方法的具體用法?Python psutil.ZombieProcess怎麽用?Python psutil.ZombieProcess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在psutil的用法示例。


在下文中一共展示了psutil.ZombieProcess方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def check(self):
        """
        Check that the service is running and consistent with pid file(s).

        Returns True or False.
        """
        # Set of pids (strings) where the command string matches what we are
        # looking for.
        detected_pids = set()

        # Set of pids (strings) that are both running processes and found in
        # pid files.
        consistent_pids = set()

        # Search for running processes that match our command string.
        for proc in psutil.process_iter():
            try:
                if self.cmdstring in proc.name():
                    detected_pids.add(str(proc.pid))

            # We could also get psutil.ZombieProcess or
            # psutil.AccessDenied.  We want those to be logged.
            except psutil.NoSuchProcess:
                pass

        # Search for pid file(s) and check consistency.
        for pidfile in self.pidfiles:
            for path in glob.iglob(pidfile):
                with open(path, 'r') as source:
                    pid = source.read().strip()

                if pid in detected_pids:
                    consistent_pids.add(pid)
                else:
                    # Delete the stale pid file.
                    os.remove(path)

        return len(consistent_pids) > 0 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:40,代碼來源:procmon.py

示例2: test_zombie_process__repr__

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_zombie_process__repr__(self, func=repr):
        self.assertEqual(
            repr(psutil.ZombieProcess(321)),
            "psutil.ZombieProcess process still exists but it's a zombie "
            "(pid=321)")
        self.assertEqual(
            repr(psutil.ZombieProcess(321, name='foo')),
            "psutil.ZombieProcess process still exists but it's a zombie "
            "(pid=321, name='foo')")
        self.assertEqual(
            repr(psutil.ZombieProcess(321, name='foo', ppid=1)),
            "psutil.ZombieProcess process still exists but it's a zombie "
            "(pid=321, name='foo', ppid=1)")
        self.assertEqual(
            repr(psutil.ZombieProcess(321, msg='foo')),
            "psutil.ZombieProcess foo") 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:test_misc.py

示例3: test_ad_on_process_creation

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_ad_on_process_creation(self):
        # We are supposed to be able to instantiate Process also in case
        # of zombie processes or access denied.
        with mock.patch.object(psutil.Process, 'create_time',
                               side_effect=psutil.AccessDenied) as meth:
            psutil.Process()
            assert meth.called
        with mock.patch.object(psutil.Process, 'create_time',
                               side_effect=psutil.ZombieProcess(1)) as meth:
            psutil.Process()
            assert meth.called
        with mock.patch.object(psutil.Process, 'create_time',
                               side_effect=ValueError) as meth:
            with self.assertRaises(ValueError):
                psutil.Process()
            assert meth.called 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:test_misc.py

示例4: test_exe_mocked

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_exe_mocked(self):
        with mock.patch('psutil._pslinux.readlink',
                        side_effect=OSError(errno.ENOENT, "")) as m1:
            with mock.patch('psutil.Process.cmdline',
                            side_effect=psutil.AccessDenied(0, "")) as m2:
                # No such file error; might be raised also if /proc/pid/exe
                # path actually exists for system processes with low pids
                # (about 0-20). In this case psutil is supposed to return
                # an empty string.
                ret = psutil.Process().exe()
                assert m1.called
                assert m2.called
                self.assertEqual(ret, "")

                # ...but if /proc/pid no longer exist we're supposed to treat
                # it as an alias for zombie process
                with mock.patch('psutil._pslinux.os.path.lexists',
                                return_value=False):
                    self.assertRaises(
                        psutil.ZombieProcess, psutil.Process().exe) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:test_linux.py

示例5: is_process_running

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def is_process_running(process_name, plex_container=None):
    try:
        for process in psutil.process_iter():
            if process.name().lower() == process_name.lower():
                if not plex_container:
                    return True, process, plex_container
                # plex_container was not None
                # we need to check if this processes is from the container we are interested in
                get_pid_container = "docker inspect --format '{{.Name}}' \"$(cat /proc/%s/cgroup |head -n 1 " \
                                    "|cut -d / -f 3)\" | sed 's/^\///'" % process.pid
                process_container = run_command(get_pid_container, True)
                logger.debug("Using: %s", get_pid_container)
                logger.debug("Docker Container For PID %s: %r", process.pid,
                             process_container.strip() if process_container is not None else 'Unknown???')
                if process_container is not None and isinstance(process_container, str) and \
                        process_container.strip().lower() == plex_container.lower():
                    return True, process, process_container.strip()

        return False, None, plex_container
    except psutil.ZombieProcess:
        return False, None, plex_container
    except Exception:
        logger.exception("Exception checking for process: '%s': ", process_name)
        return False, None, plex_container 
開發者ID:l3uddz,項目名稱:plex_autoscan,代碼行數:26,代碼來源:utils.py

示例6: check_services

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def check_services(service_name):
    """
    check to see if certain services ar started
    """
    try:
        all_processes = set()
        for pid in psutil.pids():
            running_proc = psutil.Process(pid)
            all_processes.add(" ".join(running_proc.cmdline()).strip())
        for proc in list(all_processes):
            if service_name in proc:
                return True
        return False
    except psutil.ZombieProcess as e:
        # zombie processes appear to happen on macOS for some reason
        # so we'll just kill them off
        pid = str(e).split("=")[-1].split(")")[0]
        os.kill(int(pid), 0)
        return True 
開發者ID:NullArray,項目名稱:AutoSploit,代碼行數:21,代碼來源:settings.py

示例7: _is_skip_process_running

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def _is_skip_process_running(self, user: str) -> bool:
        user_processes = []
        for process in psutil.process_iter():
            try:
                if process.username() == user:
                    user_processes.append(process.name())
            except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied):
                # ignore processes which have disappeared etc.
                pass

        for process in user_processes:
            if self._ignore_process_re.match(process) is not None:
                self.logger.debug(
                    "Process %s with pid %s matches the ignore regex '%s'."
                    " Skipping idle time check for this user.",
                    process.name(),
                    process.pid,
                    self._ignore_process_re,
                )
                return True

        return False 
開發者ID:languitar,項目名稱:autosuspend,代碼行數:24,代碼來源:activity.py

示例8: location

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def location(pid):
    p = get_process(pid)
    if hasattr(p, "location"):
        return p.location
    try:
        path = p.cmdline()[0]
    except psutil.AccessDenied:
        path = os.popen("ps %d" % pid).read()
    except (AttributeError, IndexError, psutil.NoSuchProcess, psutil.ZombieProcess):
        return ""
    try:
        path = re.sub(r".*[0-9] (/[^-]*)-*.*", r"\1", path.split('\n')[-2]).strip()
    except:
        pass
    p.location = path
    return path 
開發者ID:laffra,項目名稱:happymac,代碼行數:18,代碼來源:process.py

示例9: _check_connections

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def _check_connections(proc: psutil.Process, laddr: Tuple) -> bool:
    try:
        return laddr in [i.laddr for i in proc.connections()]
    except psutil.AccessDenied:
        return False
    except psutil.ZombieProcess:
        return False
    except psutil.NoSuchProcess:
        return False 
開發者ID:eth-brownie,項目名稱:brownie,代碼行數:11,代碼來源:rpc.py

示例10: checkIfProcessRunning

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def checkIfProcessRunning(processName):
    '''
    Check if there is any running process that contains the given name processName.
    '''
    #Iterate over the all the running process
    for proc in psutil.process_iter():
        try:
            # Check if process name contains the given name string.
            if processName.lower() in proc.name().lower():
                return True
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    return False; 
開發者ID:sevagas,項目名稱:macro_pack,代碼行數:15,代碼來源:utils.py

示例11: get_jobs

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def get_jobs(self, job_group):
        prefix = REDIS_JOBS_GROUP_PREFIX.format(job_group)
        result = {}

        jobs_map = self.SR.hgetall(prefix)

        for jobid, jobdata in jobs_map.iteritems():
            try:
                jobdata = json.loads(jobdata)

                if jobdata['status'] == 'RUNNING':
                    jobpid = jobdata['pid']
                    job_status = self._get_job_status(jobpid, jobdata['hash'])
                    jobdata.update(job_status)

                result[jobid] = jobdata

            except (ValueError, KeyError, psutil.ZombieProcess, psutil.AccessDenied):
                LOG.error('Invalid job value - deleting job {}::{}'.format(job_group, jobid))
                self.delete_job(job_group, jobid)
                continue

            if jobdata['status'] == 'DONE' and 'collected' not in jobdata:
                if jobid not in self.running_jobs[job_group]:
                    self._collect_job(jobdata)
                    self.SR.hset(job_group, jobid, json.dumps(jobdata))

        return result 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:30,代碼來源:jobs.py

示例12: test_process__repr__

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_process__repr__(self, func=repr):
        p = psutil.Process()
        r = func(p)
        self.assertIn("psutil.Process", r)
        self.assertIn("pid=%s" % p.pid, r)
        self.assertIn("name=", r)
        self.assertIn(p.name(), r)
        with mock.patch.object(psutil.Process, "name",
                               side_effect=psutil.ZombieProcess(os.getpid())):
            p = psutil.Process()
            r = func(p)
            self.assertIn("pid=%s" % p.pid, r)
            self.assertIn("zombie", r)
            self.assertNotIn("name=", r)
        with mock.patch.object(psutil.Process, "name",
                               side_effect=psutil.NoSuchProcess(os.getpid())):
            p = psutil.Process()
            r = func(p)
            self.assertIn("pid=%s" % p.pid, r)
            self.assertIn("terminated", r)
            self.assertNotIn("name=", r)
        with mock.patch.object(psutil.Process, "name",
                               side_effect=psutil.AccessDenied(os.getpid())):
            p = psutil.Process()
            r = func(p)
            self.assertIn("pid=%s" % p.pid, r)
            self.assertNotIn("name=", r) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:29,代碼來源:test_misc.py

示例13: test_zombie_process_is_running_w_exc

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_zombie_process_is_running_w_exc(self):
        # Emulate a case where internally is_running() raises
        # ZombieProcess.
        p = psutil.Process()
        with mock.patch("psutil.Process",
                        side_effect=psutil.ZombieProcess(0)) as m:
            assert p.is_running()
            assert m.called 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:test_process.py

示例14: test_exe

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_exe(self):
        self.assertRaises(psutil.ZombieProcess, self.p.exe) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:4,代碼來源:test_osx.py

示例15: test_cmdline

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import ZombieProcess [as 別名]
def test_cmdline(self):
        self.assertRaises(psutil.ZombieProcess, self.p.cmdline) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:4,代碼來源:test_osx.py


注:本文中的psutil.ZombieProcess方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。