title: Timeout function with clean exit
body: <p>I'm trying to implement something like this in python:</p>
  <pre><code>obj = MyObj()
  obj.run_task()
  
  # if run_task() takes more than 10 seconds.
  obj.clean_exit() # contains logic to exit the task cleanly
  </code></pre>
  <p><code>MyObj</code> or <code>run_task()</code> cannot contain the timing logic. It has to be external. How do I do this in python ? I'm looking for something similar to this <a href="https://stackoverflow.com/questions/492519/timeout-on-a-function-call">SO question</a> , but do not want to terminate the task - just need to call the clean_exit() method after 10 seconds. I'm a noob in python.</p>