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

Process has no attribute info - process_iter from psutil #10195

Closed
emcek opened this issue May 21, 2023 · 3 comments · Fixed by #10275
Closed

Process has no attribute info - process_iter from psutil #10195

emcek opened this issue May 21, 2023 · 3 comments · Fixed by #10275
Labels
stubs: false positive Type checkers report false errors

Comments

@emcek
Copy link

emcek commented May 21, 2023

Proccess object do not have info attribute, but code form ps.py is working fine.

ps.py

from psutil import process_iter

def proc_is_running(name: str) -> int:
    for proc in process_iter(['pid', 'name']):
        if name in proc.info['name']:
            return proc.info['pid']
    return 0

pip list

mypy                      1.3.0
mypy-extensions           1.0.0
types-psutil              5.9.5.12

mypy ps.py

ps.py:6: error: "Process" has no attribute "info"  [attr-defined]
ps.py:7: error: "Process" has no attribute "info"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)
@srittau
Copy link
Collaborator

srittau commented May 22, 2023

info seems to be added to Process dynamically by process_iter() if the attrs argument was provided:

https://github.com/giampaolo/psutil/blob/49aba759744c06fb3a6fa998155428520f161734/psutil/__init__.py#L1423-L1428

I think the best we can do is to add Process.info with a comment that it only exists when constructed through process_iter().

@srittau srittau added the stubs: false positive Type checkers report false errors label May 22, 2023
@emcek
Copy link
Author

emcek commented May 22, 2023

Yes, this is dynamic behavior.

@sobolevn
Copy link
Member

I've sent giampaolo/psutil#2260 to fix it upstream, later we can add info as a regular attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants