def setCPUAffinity():
"""
:note: Child processes inherit the parent's affinity.
"""
cpus = multiprocessing.cpu_count()
libc = cdll.LoadLibrary("libc.so.6")
# Using zero as first parameter means "self PID"
res = libc.sched_setaffinity(0, 4, byref(c_int(0x00000001 << (cpus - 1))))
# Give our process a chance to migrate to a different CPU if necessary
time.sleep(0.25)
return res
评论列表
文章目录