Python Forum

Full Version: TimeOut a function in a class ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone !

Here is my problem : I have defined a class, where I have defined some functions. In the __init__ of my class I can call some of the defined functions . The problem is that some of these functions can sometimes take a long time to execute. How can I set a timeout in these functions, so that they stop if they take too long?

For example :

class test:
def __init__(self):
self.do_actions_1()
self.do_actions_2()

def do_actions_1(self):
"bla bla bla bla bla"
def do_actions_2(self):
"bla bla bla bla bla"

If one of these actions takes too long, how can I stop it?

Thank you for your answer! :)
There are some projects to do that in Pypi, such as timeout-decorator