Threads are owned by the process that starts them. You can get the process ID with os.getpid()
.
The process ID won't change between threads:
>>> import os
>>> import threading
>>>
>>> def print_process_id():
... print(threading.current_thread(), os.getpid())
...
>>>
>>> threading.Thread(target=print_process_id).start()
<Thread(Thread-1, started 123145410715648)> 62999
>>> threading.Thread(target=print_process_id).start()
<Thread(Thread-2, started 123145410715648)> 62999
>>> threading.Thread(target=print_process_id).start()
<Thread(Thread-3, started 123145410715648)> 62999
>>> threading.Thread(target=print_process_id).start()
<Thread(Thread-4, started 123145410715648)> 62999
>>>
If you're looking to know which physical/logical CPU core is currently running your code and you're on a supported platform, you could use the psutil module, as described in https://stackoverflow.com/a/56431370/51685.