是否有可能重新启动python multiprocessing中已经终止的进程?

Rud*_*ram 5 python python-multiprocessing

这是我的问题的示例代码:

import multiprocessing, time
def nopr():
        i=0
        while 1:
                i = i+1
                print i
                time.sleep(1)

p = multiprocessing.Process(target =  nopr)
print "process started"
p.start()
time.sleep(04)
print "process ended"
p.terminate()
time.sleep(1)


p.start()
Run Code Online (Sandbox Code Playgroud)

zou*_*a13 5

不,您无法启动终止的进程,必须重新创建它:

import multiprocessing, time
def nopr():
    i=0
    while 1:
        i = i+1
        print i
        time.sleep(1)

p = multiprocessing.Process(target =  nopr)
print "process started"
p.start()
time.sleep(04)
print "process ended"
p.terminate()
time.sleep(1)

p = multiprocessing.Process(target =  nopr) # recreate
p.start()
Run Code Online (Sandbox Code Playgroud)