diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-01-30 14:22:48 +0100 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-01-30 14:22:48 +0100 |
| commit | 8b57f42f0453804ae6d3bab7ef34d3a49f5cb6f1 (patch) | |
| tree | ab917593f17988c5dbd0c064dbdc2ef277304dee /docs | |
| parent | 53be3ab5de8212e0164030bfd44f835b63ea82c0 (diff) | |
| download | psutil-8b57f42f0453804ae6d3bab7ef34d3a49f5cb6f1.tar.gz | |
#956: cpu_affinity([]) can now be used as an alias to set affinity against all eligible CPUs.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/index.rst | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/docs/index.rst b/docs/index.rst index 5ccc11b3..645df8df 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1214,32 +1214,35 @@ Process class Get or set process current `CPU affinity <http://www.linuxjournal.com/article/6799?page=0,0>`__. - CPU affinity consists in telling the OS to run a certain process on a - limited set of CPUs only. + CPU affinity consists in telling the OS to run a process on a limited set + of CPUs only. On Linux this is done via the ``taskset`` command. - The number of eligible CPUs can be obtained with - ``list(range(psutil.cpu_count()))``. - ``ValueError`` will be raised on set in case an invalid CPU number is - specified. + If no argument is passed it returns the current CPU affinity as a list + of integers. + If passed it must be a list of integers specifying the new CPUs affinity. + If an empty list is passed all eligible CPUs are assumed (and set); + on Linux this may not necessarily mean all available CPUs as in + ``list(range(psutil.cpu_count()))``). >>> import psutil >>> psutil.cpu_count() 4 >>> p = psutil.Process() - >>> p.cpu_affinity() # get + >>> # get + >>> p.cpu_affinity() [0, 1, 2, 3] - >>> p.cpu_affinity([0]) # set; from now on, process will run on CPU #0 only + >>> # set; from now on, process will run on CPU #0 and #1 only + >>> p.cpu_affinity([0, 1]) >>> p.cpu_affinity() - [0] - >>> - >>> # reset affinity against all CPUs - >>> all_cpus = list(range(psutil.cpu_count())) - >>> p.cpu_affinity(all_cpus) - >>> + [0, 1] + >>> # reset affinity against all eligible CPUs + >>> p.cpu_affinity([]) Availability: Linux, Windows, FreeBSD .. versionchanged:: 2.2.0 added support for FreeBSD + .. versionchanged:: 5.1.0 an empty list can be passed to set affinity + against all eligible CPUs. .. method:: cpu_num() |
