Assigning taskset to specific Python process (without using PID)

939 Views Asked by At

So I have a Python3 process that needs to be assigned to the 4th CPU core (CPU Affinity 3), currently it's used in 0-2. I added isolcpus=3 to the cmdline.txt in boot and I type the following in terminal:

sudo taskset -cp 3 PID

The thing is, whenever I close and start the Python script, the PID changes so I'd have to manually find the PID of that Python process and do taskset on it again. Is there a more efficient way for me to automatically start that Python process with the taskset -cp 3 command?

Thanks!

1

There are 1 best solutions below

1
On

I recommend utilizing psutil instead. Please see the following answer --

https://stackoverflow.com/a/40856471/13261176