import threading import os import sys class ForkThread(threading.Thread): def run(self): print("thread: before fork", list(threading.enumerate())) pid = os.fork() if pid: # parent: wait for the child os.waitpid(pid, 0) return # child print("thread: after fork", list(threading.enumerate())) print("thread: after fork: raise") raise Exception("what happens here?") #sys.exit(1) thread = ForkThread() print("main thread: spawn fork thread") thread.start() thread.join() print("main thread: done")