there is any way to launch program by its API using python and run it on a specified core?
i need to launch a cpu-expensive application about 5 times and run it on different core in order to save time.
i’m using windows
Advertisement
Answer
The process can set its own affinity, here is what I do (you can change the mask, or make it a parameter, to identify which cores you want to use.)
JavaScript
x
8
1
import win32api, win32con, win32process
2
3
def setaffinity():
4
pid = win32api.GetCurrentProcessId()
5
mask = 128 # core 7
6
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
7
win32process.SetProcessAffinityMask(handle, mask)
8