Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Thenative_thread_id field of thePyThreadState object is not updated after a fork on Linux (at least). This means that child processes spawned by the main thread of the parent process will have a main thread with the parent thread ID.
Thenative_thread_id is meant to be consumed by tools likeAustin and therefore the behaviour is easily observed with these tools. One way to reproduce this is to profile this with Austin
importmultiprocessingdeffact(n):f=1foriinrange(1,n+1):f*=ireturnfdefdo(N):n=1for_inrange(N):fact(n)n+=1if__name__=="__main__":importsystry:nproc=int(sys.argv[1])exceptException:nproc=2processes= []for_inrange(nproc):process=multiprocessing.Process(target=do,args=(3000,))process.start()processes.append(process)forprocessinprocesses:process.join(timeout=5)
and observe that the reported thread IDs coincide with the parent's PID.
Your environment
- CPython versions tested on: 3.11.1
- Operating system and architecture: Ubuntu 22.04 (amd64)