baweaver / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
>>> 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 reported on code.google.com by g.rodola on 3 Dec 2013 at 10:57

GoogleCodeExporter commented 8 years ago
Implemented in revision b5e078d15dc3.

Original comment by g.rodola on 3 Dec 2013 at 11:20

GoogleCodeExporter commented 8 years ago
Closing out as fixed as 2.0.0 version is finally out.

Original comment by g.rodola on 10 Mar 2014 at 11:36