How to run a Python program ona specific CPU core

Question:

Say I have a python file – file1.py with arg –in

python file1.py --in 10

I have an 8-core Unix machine, I want to run the same script 8 times (infinite loop) (diff –in value) which should run in 8 different cores, like

python file1.py --in 10 –> in core 1

python file1.py --in 20 –> in core 2

python file1.py --in 130 –> in core 3

.. so on

How to implement this? How do I specify which core to run?

python file1.py --in 10 &

python file1.py --in 20 &

python file1.py --in 130 &

If I run it like this, will it run on the same core or different cores?

Asked By: keerthan kumar

||

Answers:

Try taskset

taskset -c 1 python file1.py --in 10
taskset -c 2 python file1.py --in 20
taskset -c 3 python file1.py --in 130
Answered By: billz
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.