title: How to execute code just before terminating the process in python?
body: <p>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 <code>atexit.register</code> for the python program.</p>
  
  <p>I have a method worker which looks:</p>
  
  <p>def worker():
    while True:
    print('work')
    time.sleep(2)
    return</p>
  
  <p>I run it by:</p>
  
  <p>proc = multiprocessing.Process(target=worker, args=())
    proc.start()</p>
  
  <p>My goal is to execute some extra code just before terminating it, which I do by:</p>
  
  <p>proc.terminate()</p>