import time, os, thread def f(): print "I am thread %d in process %d" % (thread.get_ident(),os.getpid()) time.sleep(1) ident = thread.start_new_thread(f, ()) print "started thread %d in process %d" % (ident, os.getpid()) time.sleep(0.5) # give thread a chance to start pid = os.fork() if pid == 0: ident = thread.start_new_thread(f, ()) print "started thread %d in process %d" % (ident, os.getpid()) time.sleep(0.5) # give thread a chance to start os._exit(0) os.waitpid(pid, 0)