exitstat def child()global exitstat process global names exitstat + shared by all threads threadid thread get_ident(print('hello from child'threadidexitstatthread exit(print('never reached'def parent()while truethread start_new_thread(child()if input(=' 'break if __name__ ='__main__'parent(the following shows this script in action on windowsunlike forksthreads run in the standard version of python on windowstoo thread identifiers created by python differ each time--they are arbitrary but unique among all currently active threads and so may be used as dictionary keys to keep per-thread information ( thread' id may be reused after it exits on some platforms) :\pp \system\exitspython testexit_thread py hello from child hello from child hello from child hello from child notice how the value of this script' global exitstat is changed by each threadbecause threads share global memory within the process in factthis is often how threads communicate in general rather than exit status codesthreads assign module-level globals or change shared mutable objects in-place to signal conditionsand they use thread module locks and queues to synchronize access to shared items if needed this script might need to synchronizetooif it ever does something more realistic--for global counter changesbut even print and input may have to be synchronized if they overlap stream access badly on some platforms for this simple demowe forego locks by assuming threads won' mix their operations oddly as we've learneda thread normally exits silently when the function it runs returnsand the function return value is ignored optionallythe _thread exit function can be called to terminate the calling thread explicitly and silently this call works almost exactly like sys exit (but takes no return status argument)and it works by raising systemexit exception in the calling thread because of thata thread can also prematurely end by calling sys exit or by directly raising systemexit be sure not to call os _exit within thread functionthough--doing so can have odd results (the last time program exits