Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CPUSet
✓ import cpuset
✗ from cpuset import CPUSet
This quickstart demonstrates how to create and manipulate `CPUSet` objects. It also shows how to query the current process's affinity on Linux, with a note about the permissions often required for setting affinity.
import cpuset
import platform
print(f"Running on OS: {platform.system()}\n")
# Create a new empty cpuset
s = cpuset.CPUSet()
s.add_cpu(0)
s.add_cpu(1)
s.add_cpu(2)
print(f"Created CPUSet (0,1,2): {s.as_list()}")
print(f"As string: {s.as_str()}")
print(f"As canonical string: {s.as_canonical_str()}") # will be "0-2"
print(f"As bitmask: {hex(s.as_bitmask())}") # 0x7
# Create from a string representation
s_from_str = cpuset.CPUSet("0-3,5")
print(f"\nCPUSet from string '0-3,5': {s_from_str.as_list()}")
if platform.system() == "Linux":
print("\nAttempting to query current process affinity (Linux-only):")
try:
current_affinity = cpuset.get_cpuset_for_current_process()
print(f" Current process affinity: {current_affinity.as_list()}")
# Uncomment to attempt setting affinity (requires appropriate permissions):
# print(f" Attempting to set process affinity to {s.as_list()}...")
# cpuset.set_cpuset_for_current_process(s)
# updated_affinity = cpuset.get_cpuset_for_current_process()
# print(f" Updated process affinity: {updated_affinity.as_list()}")
except PermissionError:
print(" Permission denied to get/set process affinity. Try running with sudo or check capabilities.")
except Exception as e:
print(f" An error occurred during system affinity call: {e}")
else:
print("\nSystem affinity functions (get/set) are only available on Linux.")
print("\nOperations on CPUSet objects are generally platform-independent:")
s_union = s | cpuset.CPUSet("3-4")
print(f"Union (0-2 | 3-4): {s_union.as_list()}") # [0,1,2,3,4]
s_intersect = s & cpuset.CPUSet("1-3")
print(f"Intersection (0-2 & 1-3): {s_intersect.as_list()}") # [1,2]
cpuset --version
Upgrade
Version history
1.0.2latest on PyPI · released Dec 1, 2020
Audit
Dependencies
No dependency data recorded yet.