summaryrefslogtreecommitdiff
path: root/psutil/_psosx.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2021-10-05 19:20:51 +0200
committerGitHub <noreply@github.com>2021-10-05 19:20:51 +0200
commite15922b9f7f389679c73ab15ab5ac237b7c0d37f (patch)
tree22d2430de16b2f7bdd235581e30f8852f07ef0a4 /psutil/_psosx.py
parenta02ebdedc945fedb7173edfed5ad4d6f7a04a760 (diff)
downloadpsutil-e15922b9f7f389679c73ab15ab5ac237b7c0d37f.tar.gz
[macOS] dynamic set buffer size for process connections/fds (fixes #1901) (#1903)
Diffstat (limited to 'psutil/_psosx.py')
-rw-r--r--psutil/_psosx.py57
1 files changed, 10 insertions, 47 deletions
diff --git a/psutil/_psosx.py b/psutil/_psosx.py
index d948cc15..eda70d21 100644
--- a/psutil/_psosx.py
+++ b/psutil/_psosx.py
@@ -4,7 +4,6 @@
"""macOS platform implementation."""
-import contextlib
import errno
import functools
import os
@@ -354,32 +353,6 @@ def wrap_exceptions(fun):
return wrapper
-@contextlib.contextmanager
-def catch_zombie(proc):
- """There are some poor C APIs which incorrectly raise ESRCH when
- the process is still alive or it's a zombie, or even RuntimeError
- (those who don't set errno). This is here in order to solve:
- https://github.com/giampaolo/psutil/issues/1044
- """
- try:
- yield
- except (OSError, RuntimeError) as err:
- if isinstance(err, RuntimeError) or err.errno == errno.ESRCH:
- try:
- # status() is not supposed to lie and correctly detect
- # zombies so if it raises ESRCH it's true.
- status = proc.status()
- except NoSuchProcess:
- raise err
- else:
- if status == _common.STATUS_ZOMBIE:
- raise ZombieProcess(proc.pid, proc._name, proc._ppid)
- else:
- raise AccessDenied(proc.pid, proc._name)
- else:
- raise
-
-
class Process(object):
"""Wrapper class around underlying C implementation."""
@@ -402,8 +375,7 @@ class Process(object):
@memoize_when_activated
def _get_pidtaskinfo(self):
# Note: should work for PIDs owned by user only.
- with catch_zombie(self):
- ret = cext.proc_pidtaskinfo_oneshot(self.pid)
+ ret = cext.proc_pidtaskinfo_oneshot(self.pid)
assert len(ret) == len(pidtaskinfo_map)
return ret
@@ -422,18 +394,15 @@ class Process(object):
@wrap_exceptions
def exe(self):
- with catch_zombie(self):
- return cext.proc_exe(self.pid)
+ return cext.proc_exe(self.pid)
@wrap_exceptions
def cmdline(self):
- with catch_zombie(self):
- return cext.proc_cmdline(self.pid)
+ return cext.proc_cmdline(self.pid)
@wrap_exceptions
def environ(self):
- with catch_zombie(self):
- return parse_environ_block(cext.proc_environ(self.pid))
+ return parse_environ_block(cext.proc_environ(self.pid))
@wrap_exceptions
def ppid(self):
@@ -442,8 +411,7 @@ class Process(object):
@wrap_exceptions
def cwd(self):
- with catch_zombie(self):
- return cext.proc_cwd(self.pid)
+ return cext.proc_cwd(self.pid)
@wrap_exceptions
def uids(self):
@@ -516,8 +484,7 @@ class Process(object):
if self.pid == 0:
return []
files = []
- with catch_zombie(self):
- rawlist = cext.proc_open_files(self.pid)
+ rawlist = cext.proc_open_files(self.pid)
for path, fd in rawlist:
if isfile_strict(path):
ntuple = _common.popenfile(path, fd)
@@ -530,8 +497,7 @@ class Process(object):
raise ValueError("invalid %r kind argument; choose between %s"
% (kind, ', '.join([repr(x) for x in conn_tmap])))
families, types = conn_tmap[kind]
- with catch_zombie(self):
- rawlist = cext.proc_connections(self.pid, families, types)
+ rawlist = cext.proc_connections(self.pid, families, types)
ret = []
for item in rawlist:
fd, fam, type, laddr, raddr, status = item
@@ -544,8 +510,7 @@ class Process(object):
def num_fds(self):
if self.pid == 0:
return 0
- with catch_zombie(self):
- return cext.proc_num_fds(self.pid)
+ return cext.proc_num_fds(self.pid)
@wrap_exceptions
def wait(self, timeout=None):
@@ -553,13 +518,11 @@ class Process(object):
@wrap_exceptions
def nice_get(self):
- with catch_zombie(self):
- return cext_posix.getpriority(self.pid)
+ return cext_posix.getpriority(self.pid)
@wrap_exceptions
def nice_set(self, value):
- with catch_zombie(self):
- return cext_posix.setpriority(self.pid, value)
+ return cext_posix.setpriority(self.pid, value)
@wrap_exceptions
def status(self):