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

as_dict() may not work if Process acquires new names #813

Closed
giampaolo opened this issue Apr 30, 2016 · 1 comment
Closed

as_dict() may not work if Process acquires new names #813

giampaolo opened this issue Apr 30, 2016 · 1 comment
Labels

Comments

@giampaolo
Copy link
Owner

giampaolo commented Apr 30, 2016

Internally, Process.as_dict uses dir() builtin in order to fetch all attribute/method names of the Process class in order to return their value as a dict. Unfortunately this means that if the user attaches a new name to the Process instance that will be returned as well:

import psutil
p = psutil.Process()
p.foo = '1'
print 'foo' in p.as_dict()

Even worse, if the new name refers to a callable object, that will be called. The solution is to execute dir(Process) at import time, store the names in a global variable and have as_dict rely on it.

@giampaolo giampaolo added the bug label Apr 30, 2016
@giampaolo
Copy link
Owner Author

Fixed in d1adc72f

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

No branches or pull requests

1 participant