Why python script hangs after the main process exited

Viewed 4439

I have some time consuming task in a function and i want this function to run even after the main process exited.

Code sample:

def do_time_consuming_thing():
    // do time consuming task here
    time.sleep(30)

def worker():
    print "start a child process:"
    p = multiprocessing.Process(target=do_time_consuming_thing,args=())
    p.start()
    print "child pid:%d" % p.pid
    sys.exit(0) // main process exit here.

def test():
    worker()

But when i run the above code in shell command line, i can not return to the command line prompt before the child process finishes.

How can i return to the command line prompt immediately after the sys.exit(0) finishes.

2 Answers
Related