multiprocessing - Killing a process launched from a process that has ended - Python -
i trying kill process in python, being launched process , unable find correct place place ".terminate()".
to explain myself better post example code:
from multiprocessing import process import time def function(): print "here creating function need kill" processtokill = process(target = killme) processtokill.start() def killme(): while true: print "kill me" time.sleep(0.5) if __name__ == '__main__': process1 = process(target = function) process1.start() my question is, can place processtokill.terminate(), ideally without having change overall structure of code?
you can hold onto processtokill object can kill later:
from multiprocessing import process import time def function(): print "here creating function need kill" processtokill = process(target = killme) processtokill.start() return processtokill def killme(): while true: print "kill me" time.sleep(0.5) if __name__ == '__main__': process1 = function() time.sleep(5) process1.terminate() here, i've removed wrapping of function in process object, because example seems redundant, should able same thing process runs process.
Comments
Post a Comment