After fork, the thread_info should be updated, because the tid is inherited from its parent process. So the following happened:

This happens if we use:
os.fork.
multiprocessing with the start method fork.
forkserver will not lead to this, because we only patch, but not trace.
spwan will not lead to this as well, because we use exec.
I've fixed it:

I'll open a PR later.
Code to reproduce:
fork
import os
def hello():
print("Hello World", os.getpid())
def child():
print("Child process")
hello()
def parent():
print("Parent process")
hello()
print("Hello World")
pid = os.fork()
if pid == 0:
child()
else:
parent()
os.waitpid(pid, 0)
multiprocessing with 'fork'
import multiprocessing
import os
def hello():
print("Hello World", os.getpid())
def child():
print("Child process")
hello()
def parent():
print("Parent process")
hello()
print("Hello World")
if __name__ == "__main__":
import multiprocessing as mp
mp.set_start_method("fork")
p = multiprocessing.Process(target=child)
p.start()
p.join()
parent()
After fork, the
thread_infoshould be updated, because the tid is inherited from its parent process. So the following happened:This happens if we use:
os.fork.multiprocessingwith the start methodfork.forkserverwill not lead to this, because we only patch, but not trace.spwanwill not lead to this as well, because we useexec.I've fixed it:
I'll open a PR later.
Code to reproduce:
forkmultiprocessingwith 'fork'