Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] AttributeError: 'Process' object has no attribute '_cache' #2227

Closed
MidKnightXI opened this issue Apr 12, 2023 · 3 comments
Closed

Comments

@MidKnightXI
Copy link

Summary

  • OS: macOS Ventura
  • Architecture: ARM M1 Pro
  • Psutil version: 5.9.4
  • Python version: 3.11.2
  • Type: execution

Description

psutil is crashing on macos whereas it is working on Windows 11

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_common.py", line 443, in wrapper
    ret = self._cache[fun]
          ^^^^^^^^^^^
AttributeError: 'Process' object has no attribute '_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_common.py", line 443, in wrapper
    ret = self._cache[fun]
          ^^^^^^^^^^^
AttributeError: 'Process' object has no attribute '_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_psosx.py", line 346, in wrapper
    return fun(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_common.py", line 446, in wrapper
    return fun(self)
           ^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_psosx.py", line 381, in _get_pidtaskinfo
    ret = cext.proc_pidtaskinfo_oneshot(self.pid)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ProcessLookupError: [Errno 3] No such process (originated from proc_pidinfo())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/midknight/Documents/CAU/2nd_semester/Search&Optimisation/tp/lab2/searchopt_lab2/main.py", line 190, in <module>
    p_bytes = pu.Process(p.pid).memory_info().rss
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_common.py", line 446, in wrapper
    return fun(self)
           ^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/__init__.py", line 1058, in memory_info
    return self._proc.memory_info()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_psosx.py", line 346, in wrapper
    return fun(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/psutil/_psosx.py", line 446, in memory_info
    rawtuple = self._get_pidtaskinfo()
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/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=3531)
@giampaolo
Copy link
Owner

NoSuchProcess is legitimate.

@MidKnightXI
Copy link
Author

Thank you for answering that fast.

Would it be possible for you to detail your answer on why I'm not getting this error on windows but on macos, I'm not really sure to understand?

Thank you in advance 👍🏻

@giampaolo
Copy link
Owner

Processes can disappear at any time, so you should always be ready to catch NoSuchProcess in a try/except. This would be a bug if NoSuchProcess is raised but process still exist (pid_exists() returning True).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants