Get thread pid

Alejandro alejandro.weinstein at
Thu Jan 29 17:04:49 CET 2009


I have Python program running under Linux, that create several
threads, and I want to now the corresponding PID of the threads.

In each of the threads I have

def run(self):
    pid = os.getpid()
    logger.critical('process ID: %s', pid)

However, the reported PID is the father number, not the PID of the new
thread. Is there a way to get the PID of the thread?

To illustrate this further, this is the output of pstree when the PID
of the main Python thread is 9197:

$pstree -p 9197

I want each thread to report its PID number, in this case 9555, 9556,
etc., but with os.getpid() is get 9197.


More information about the Python-list mailing list