File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
15
15
"localhost"
16
16
- #579: [Windows] fixed many compiler warnings.
17
17
- #585: [FreeBSD] net_connections() may raise KeyError.
18
-
18
+ - #586: [FreeBSD] cpu_affinity() segfaults on set in case an invalid CPU
19
+ number is provided.
19
20
20
21
2.2.1 - 2015-02-02
21
22
==================
Original file line number Diff line number Diff line change @@ -406,6 +406,14 @@ def cpu_affinity_get(self):
406
406
407
407
@wrap_exceptions
408
408
def cpu_affinity_set (self , cpus ):
409
+ # Pre-emptively check if CPUs are valid because the C
410
+ # function has a weird behavior in case of invalid CPUs
411
+ #, see: https://github.com/giampaolo/psutil/issues/586
412
+ allcpus = tuple (range (len (per_cpu_times ())))
413
+ for cpu in cpus :
414
+ if cpu not in allcpus :
415
+ raise ValueError ("invalid CPU #%i (choose between %s)"
416
+ % (cpu , allcpus ))
409
417
try :
410
418
cext .proc_cpu_affinity_set (self .pid , cpus )
411
419
except OSError as err :
@@ -414,7 +422,6 @@ def cpu_affinity_set(self, cpus):
414
422
# on because the set does not overlap with the thread's
415
423
# anonymous mask>>
416
424
if err .errno in (errno .EINVAL , errno .EDEADLK ):
417
- allcpus = tuple (range (len (per_cpu_times ())))
418
425
for cpu in cpus :
419
426
if cpu not in allcpus :
420
427
raise ValueError ("invalid CPU #%i (choose between %s)"
You can’t perform that action at this time.
0 commit comments