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.