set thread affinity in python and java

1.9k Views Asked by At

When I create a thread with Java or Python I can't find the pid among the operating system threads. In fact get_ident() in Python gives me a very large number that can't be the PID.

In fact I need to set the process affinity of all other threads to the first processor core then I want to dedicate the other cores to my specific threads run in a program to create a real time environment. The threads will be less than remaining processor cores.

As I have read in stackoverflow it is not possible in Java and there will be the esigence of native calls. Can it be done in Python or I must use C/C++?

The program will be installed in a Linux machine.

2

There are 2 best solutions below

2
On

For java threads, especially under Linux, there is https://github.com/OpenHFT/Java-Thread-Affinity

2
On

I'm not sure I understand what you want exactly, but in Java I remember that I could launch multiple JVM and run my java programs on different OS processes, using inter-processes communication (socket, pipe or whatever you want) to do multi-core processing and syncronization. Knowing that, it might be possible to then set a process (whole JVM) exclusively on a core. You can get the PID of the JVM.