summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-11-08 06:13:37 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-11-08 06:13:37 +0100
commitf7e00828f33dec8c2653aaa857f4a64aa586947b (patch)
treeeda6abb0f9484f0ad69715986444464a846ccfeb
parent2ce156bc2540598a91e9c311eb1d553143d7b3aa (diff)
downloadpsutil-f7e00828f33dec8c2653aaa857f4a64aa586947b.tar.gz
#615: disable cpu_affinity() on OpenBSD 'cause it's not supported
-rw-r--r--docs/index.rst2
-rw-r--r--psutil/__init__.py2
-rw-r--r--psutil/_psbsd.py54
3 files changed, 30 insertions, 28 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 9a9622dc..d47a64cf 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -960,7 +960,7 @@ Process class
>>> p.cpu_affinity(all_cpus)
>>>
- Availability: Linux, Windows, BSD
+ Availability: Linux, Windows, FreeBSD
.. versionchanged:: 2.2.0 added support for FreeBSD
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 4c96746f..47ef5cfd 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -715,7 +715,7 @@ class Process(object):
else:
return self._proc.rlimit(resource, limits)
- # Windows, Linux and BSD only
+ # Windows, Linux and FreeBSD only
if hasattr(_psplatform.Process, "cpu_affinity_get"):
def cpu_affinity(self, cpus=None):
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index dd8418bc..7b7b1d2c 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -466,30 +466,32 @@ class Process(object):
memory_maps = _not_implemented
num_fds = _not_implemented
- @wrap_exceptions
- def cpu_affinity_get(self):
- return cext.proc_cpu_affinity_get(self.pid)
+ if FREEBSD:
+ @wrap_exceptions
+ def cpu_affinity_get(self):
+ return cext.proc_cpu_affinity_get(self.pid)
- @wrap_exceptions
- def cpu_affinity_set(self, cpus):
- # Pre-emptively check if CPUs are valid because the C
- # function has a weird behavior in case of invalid CPUs,
- # see: https://github.com/giampaolo/psutil/issues/586
- allcpus = tuple(range(len(per_cpu_times())))
- for cpu in cpus:
- if cpu not in allcpus:
- raise ValueError("invalid CPU #%i (choose between %s)"
- % (cpu, allcpus))
- try:
- cext.proc_cpu_affinity_set(self.pid, cpus)
- except OSError as err:
- # 'man cpuset_setaffinity' about EDEADLK:
- # <<the call would leave a thread without a valid CPU to run
- # on because the set does not overlap with the thread's
- # anonymous mask>>
- if err.errno in (errno.EINVAL, errno.EDEADLK):
- for cpu in cpus:
- if cpu not in allcpus:
- raise ValueError("invalid CPU #%i (choose between %s)"
- % (cpu, allcpus))
- raise
+ @wrap_exceptions
+ def cpu_affinity_set(self, cpus):
+ # Pre-emptively check if CPUs are valid because the C
+ # function has a weird behavior in case of invalid CPUs,
+ # see: https://github.com/giampaolo/psutil/issues/586
+ allcpus = tuple(range(len(per_cpu_times())))
+ for cpu in cpus:
+ if cpu not in allcpus:
+ raise ValueError("invalid CPU #%i (choose between %s)"
+ % (cpu, allcpus))
+ try:
+ cext.proc_cpu_affinity_set(self.pid, cpus)
+ except OSError as err:
+ # 'man cpuset_setaffinity' about EDEADLK:
+ # <<the call would leave a thread without a valid CPU to run
+ # on because the set does not overlap with the thread's
+ # anonymous mask>>
+ if err.errno in (errno.EINVAL, errno.EDEADLK):
+ for cpu in cpus:
+ if cpu not in allcpus:
+ raise ValueError(
+ "invalid CPU #%i (choose between %s)" % (
+ cpu, allcpus))
+ raise