Skip to content

handle exception for psutil.NoSuchProcess along with psutil.AccessDenied - #401

Open
yeggor wants to merge 1 commit into
pythonprofilers:masterfrom
yeggor:bugfix/no-such-process
Open

handle exception for psutil.NoSuchProcess along with psutil.AccessDenied#401
yeggor wants to merge 1 commit into
pythonprofilers:masterfrom
yeggor:bugfix/no-such-process

Conversation

@yeggor

Copy link
Copy Markdown

Hi. I've noticed that there can be a condition where process will be killed between

process=psutil.Process(pid)
and
mem=getattr(process, meminfo_attr)()[0] /_TWO_20

In this case, we get an exception psutil.NoSuchProcess: process no longer exists (pid=...), that we have to handle the same way as it's done here:

except (psutil.NoSuchProcess, psutil.AccessDenied):

@yeggor

Copy link
Copy Markdown
Author

here is trace from mprof run in case of triggered issue:

 File "/Users/user/pyenv/lib/python3.11/site-packages/mprof.py", line 283, in run_action
mp.memory_usage(proc=p, interval=args.interval, timeout=args.timeout, timestamps=True,
File "/Users/user/pyenv/lib/python3.11/site-packages/memory_profiler.py", line 405, in memory_usage
mem_usage = _get_memory(
^^^^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/memory_profiler.py", line 221, in _get_memory
return tools[backend]()
^^^^^^^^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/memory_profiler.py", line 140, in ps_util_tool
mem = getattr(process, meminfo_attr)()[0] / _TWO_20
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/psutil/_common.py", line 486, in wrapper
raise raise_from(err, None)
^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 3, in raise_from
File "/Users/user/pyenv/lib/python3.11/site-packages/psutil/_common.py", line 484, in wrapper
return fun(self)
^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/psutil/__init__.py", line 1084, in memory_info
return self._proc.memory_info()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/psutil/_psosx.py", line 346, in wrapper
return fun(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/psutil/_psosx.py", line 444, in memory_info
rawtuple = self._get_pidtaskinfo()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/pyenv/lib/python3.11/site-packages/psutil/_psosx.py", line 351, in wrapper
raise NoSuchProcess(self.pid, self._name)
psutil.NoSuchProcess: process no longer exists (pid=80279)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yeggor