This question concerns multiprocessing in python. I want to execute some code when I terminate the process, to be more specific just before it will be terminated. I'm looking for a solution which works as atexit.register for the python program.
I have a method worker which looks:
def worker():
while True:
print('work')
time.sleep(2)
return
I run it by:
proc = multiprocessing.Process(target=worker, args=())
proc.start()
My goal is to execute some extra code just before terminating it, which I do by:
proc.terminate()
process.terminate()asks the operating system to kill withSIGTERM. So nofinallyhandlers etc. will be executed.SIGTERMsignal handler. Seesignal.signalin docs.python.org/3.4/library/signal.html