I want to have a timeout for a function (rest API call) in python & for that I am following this SO answer.
I already have one existing code structure where i want to have a timeout decorator. I am defining a timeout seconds in ".txt" file & passing it as a dict to main function. Something like :
class Foo():
def __init__(self, params):
self.timeout=params.get['timeout']
....
....
@timeout(self.timeout) #throws an error
def bar(arg1,arg2,arg3,argn):
pass
#handle timeout for this function by getting timeout from __init__
#As answer given in SO ,
#I need to use the self.timeout, which is throwing an error:
***signal.alarm(seconds)
TypeError: an integer is required***
#And also
***@timeout(self.timeout)
NameError: name 'self' is not defined***
@timeout(30) #Works fine without any issue
def foo_bar(arg1,arg2,arg3,argn):
pass
What am i missing ?