Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to restart the already terminated process in python multiprocessing?

Here is the example code for my question:

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()
like image 565
Rudresh Jayaram Avatar asked May 26 '16 13:05

Rudresh Jayaram


1 Answers

No you cannot start a terminated process, you would have to recreate it :

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()
like image 167
zoubida13 Avatar answered Sep 18 '22 15:09

zoubida13