Closed GoogleCodeExporter closed 9 years ago
Preliminary Linux patch in attachment.
I'm still not sure whether I like the property-based API though.
Alternatives:
>>> p.cpu_affinity() # get
[0]
>>> p.cpu_affinity([0]) # set
>>>
...or:
>>> p.get_cpu_affinity() # get
[0]
>>> p.set_cpu_affinity([0]) # set
>>>
Original comment by g.rodola
on 21 Dec 2011 at 12:05
Attachments:
One tip regarding implementation - original affinity implementation has a bug,
which makes it unusable in some Linux environments (for example CentOS 5.5). I
am using a alternative implementation from:
http://alioth.debian.org/tracker/index.php?func=detail&aid=311537&group_id=30402
&atid=411002 which seems to work for my cases.
Would it be possible to call it in following manner:
p = psutil.Process(0)
p.cpu_affinity = [0, 1]
sp = subprocess.Popen(...)
With current affinity implementation it allows to set an affinity for spawned
process in advance.
Original comment by maciej.l...@gmail.com
on 21 Dec 2011 at 7:52
What's the problem? PID 0?
This works for me:
>>> import psutil
>>> p = psutil.Process(0)
>>> p.cpu_affinity
[0, 1]
>>> p.cpu_affinity = [0]
>>> p.cpu_affinity
[0]
>>>
Original comment by g.rodola
on 21 Dec 2011 at 11:25
Linux implementation committed in r1246.
As for now I choose the following API but I know myself, and I might change my
mind later =):
>>> get_cpu_affinity()
[0,1]
>>> set_cpu_affinity([0,1])
>>>
Original comment by g.rodola
on 23 Dec 2011 at 9:03
Windows implementation committed in r1249.
Original comment by g.rodola
on 25 Dec 2011 at 2:56
Note to self - python 3.3. exposed different sched.h functions:
http://docs.python.org/dev/whatsnew/3.3.html#os
http://bugs.python.org/issue12655
http://docs.python.org/dev/library/os.html#interface-to-the-scheduler
It might be worth to take a look and figure out whether we can include some of
those in psutil.
Original comment by g.rodola
on 17 Feb 2012 at 11:54
0.5.0 is finally out. Closing out as fixed.
Original comment by g.rodola
on 27 Jun 2012 at 6:54
[deleted comment]
Updated csets after the SVN -> Mercurial migration:
r1246 == revision 9235dc5f5a15
r1249 == revision 566889617340
Original comment by g.rodola
on 2 Mar 2013 at 12:06
Hi, is there a plan to pursue the implementation of cpu_affinity on OS X in the
future? I know Apple has made it difficult by "not exporting interfaces to
processor control"... Thanks.
Original comment by paul.qu...@gmail.com
on 9 May 2013 at 7:16
When I looked into OSX implementation it seemed this wasn't possible.
If you have any reference / pointers please share.
Original comment by g.rodola
on 9 May 2013 at 11:05
Original issue reported on code.google.com by
g.rodola
on 20 Dec 2011 at 7:08