diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-11 12:58:16 -0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-11 12:58:16 -0800 |
commit | 7199fb3b7e70f0a4d4eb720f4ad1c29f976855e3 (patch) | |
tree | a42fcc042d46f120a1d593f0f6287de44c3a3db4 | |
parent | abedd83e61ec80db5a44a744400b465f81e19735 (diff) | |
download | psutil-7199fb3b7e70f0a4d4eb720f4ad1c29f976855e3.tar.gz |
NtQuerySystemInformation on on PYPY often fails with ERROR_TOO_MANY_OPEN_FILES: force AD instead
-rw-r--r-- | psutil/_common.py | 8 | ||||
-rw-r--r-- | psutil/_pswindows.py | 16 | ||||
-rw-r--r-- | psutil/tests/test_unicode.py | 1 |
3 files changed, 22 insertions, 3 deletions
diff --git a/psutil/_common.py b/psutil/_common.py index 453c771d..9306cd15 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -790,8 +790,14 @@ def hilite(s, ok=True, bold=False): if bool(os.getenv('PSUTIL_DEBUG', 0)): + import inspect + def debug(msg): - print("psutil-debug> " + msg, file=sys.stderr) + """If PSUTIL_DEBUG env var is set, print a debug message to stderr.""" + fname, lineno, func_name, lines, index = inspect.getframeinfo( + inspect.currentframe().f_back) + print("psutil-debug [%s:%s]> %s" % (fname, lineno, msg), + file=sys.stderr) else: def debug(msg): pass diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 83793c5a..c2cdbb85 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -17,6 +17,7 @@ from . import _common from ._common import AccessDenied from ._common import conn_tmap from ._common import conn_to_ntuple +from ._common import debug from ._common import ENCODING from ._common import ENCODING_ERRS from ._common import isfile_strict @@ -80,7 +81,7 @@ __extra__all__ = [ CONN_DELETE_TCB = "DELETE_TCB" ERROR_PARTIAL_COPY = 299 - +PYPY = '__pypy__' in sys.builtin_module_names if enum is None: AF_LINK = -1 @@ -752,7 +753,18 @@ class Process(object): @wrap_exceptions @memoize_when_activated def exe(self): - exe = cext.proc_exe(self.pid) + if PYPY: + try: + exe = cext.proc_exe(self.pid) + except WindowsError as err: + # 24 = ERROR_TOO_MANY_OPEN_FILES. Not sure why this happens + # (perhaps PyPy's JIT delaying garbage collection of files?). + if err.errno == 24: + debug("%r forced into AccessDenied" % err) + raise AccessDenied(self.pid, self._name) + raise + else: + exe = cext.proc_exe(self.pid) if not PY3: exe = py2_strencode(exe) if exe.startswith('\\'): diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py index 4cc5b46f..9e459fbe 100644 --- a/psutil/tests/test_unicode.py +++ b/psutil/tests/test_unicode.py @@ -327,6 +327,7 @@ class TestNonFSAPIS(unittest.TestCase): reap_children() @unittest.skipIf(not HAS_ENVIRON, "not supported") + @unittest.skipIf(PYPY and WINDOWS, "segfaults on PYPY + WINDOWS") def test_proc_environ(self): # Note: differently from others, this test does not deal # with fs paths. On Python 2 subprocess module is broken as |