本文整理汇总了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
示例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")
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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;
示例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
示例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)
示例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
示例14: test_exe
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import ZombieProcess [as 别名]
def test_exe(self):
self.assertRaises(psutil.ZombieProcess, self.p.exe)
示例15: test_cmdline
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import ZombieProcess [as 别名]
def test_cmdline(self):
self.assertRaises(psutil.ZombieProcess, self.p.cmdline)