0

I'm trying to implement something like this in python:

obj = MyObj()
obj.run_task()

# if run_task() takes more than 10 seconds.
obj.clean_exit() # contains logic to exit the task cleanly

MyObj or run_task() 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 SO question , 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.

Neeraj
  • 2,376
  • 2
  • 24
  • 41
  • 1
    Simply replace the `raise` with your logic in the `handler` function I believe will do the trick... – Tomerikoo Nov 02 '20 at 14:29
  • 1
    [This is](https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish?noredirect=1&lq=1) a bit of a different take on the same method – Tomerikoo Nov 02 '20 at 14:31

0 Answers0