os _exit(exitstatprint('never reached'def parent()while truenewpid os fork(start new copy of process if newpid = if in copyrun child logic child(loop until 'qconsole input elsepidstatus os wait(print('parent got'pidstatus(status > )if input(=' 'break if __name__ ='__main__'parent(running this program on linuxunixor cygwin (rememberfork still doesn' work on standard windows python as write the fourth edition of this bookproduces the following sort of results[ :\pp \system\exits]python testexit_fork py hello from child parent got hello from child parent got hello from child parent got if you study this output closelyyou'll notice that the exit status (the last number printedis always the same--the number because forked processes begin life as copies of the process that created themthey also have copies of global memory because of thateach forked child gets and changes its own exitstat global variable without changing any other process' copy of this variable at the same timeforked processes copy and thus share file descriptorswhich is why prints go to the same place thread exits and shared state in contrastthreads run in parallel within the same process and share global memory each thread in example - changes the single shared global variableexitstat example - pp \system\exits\testexit_thread py ""spawn threads to watch shared global memory changethreads normally exit when the function they run returnsbut _thread exit(can be called to exit calling thread_thread exit is the same as sys exit and raising systemexitthreads communicate with possibly locked global varscaveatmay need to make print/input calls atomic on some platforms--shared stdout"" parallel system tools