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 objects can't be used with set()s #452

Closed
giampaolo opened this issue May 23, 2014 · 2 comments
Closed

Process objects can't be used with set()s #452

giampaolo opened this issue May 23, 2014 · 2 comments

Comments

@giampaolo
Copy link
Owner

From g.rodola on December 03, 2013 23:57:30

>>> p1 = psutil.Process(32141)
>>> p2 = psutil.Process(32141)
>>> set([p1, p2])
set([<psutil.Process(pid=32141, name='python') at 140160404497552>, 
     <psutil.Process(pid=32141, name='python') at 140160438974928>])
>>> 

It would be nice if the set could recognize the same Process instance based on 
its PID and remove duplicates.
In order to do that the Process class should override __eq__ and __hash__ 
special methods.

Long ago we attempted to introduce __eq__ but we ended up regretting it because 
introducing advanced logic in it may lead to unexpected drawbacks: 
https://code.google.com/p/psutil/issues/detail?id=211 I want to take that back 
now and make __eq__ just compare process pid (as opposed to pid + creation 
time) and consider this one of those cases where practicality beats purity.

Original issue: http://code.google.com/p/psutil/issues/detail?id=452

@giampaolo giampaolo self-assigned this May 23, 2014
@giampaolo
Copy link
Owner Author

From g.rodola on December 03, 2013 15:20:47

Implemented in revision b5e078d15dc3 .

Status: FixedInHG
Labels: -Priority-Medium Priority-High Milestone-1.3.0

@giampaolo
Copy link
Owner Author

From g.rodola on March 10, 2014 04:36:50

Closing out as fixed as 2.0.0 version is finally out.

Status: Fixed
Labels: -Milestone-1.3.0 Milestone-2.0.0

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

1 participant