You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a class like:
class A(object):
def init(self):
self.timeout=4
@timeout_decorator(self.timeout) # it dosn't work
def doanything(self):
print("do")
So, how to decorate doanything function in A class?
Thanks
The text was updated successfully, but these errors were encountered:
why would it work? your function doesn't take any time.
This worked for me (I am trying to time-limit unittest.assertEqual so I wanted to decorate it ):
from timeout_decorator import timeout, TimeoutError as CustomTimeoutError
from time import time, sleep
class TimeItOut:
def __init__(self, wait_=1, maxtime=.2):
self.wait_= wait_
# @timeout(.2) this should work for what you want, I am testing
# how to decorate an existing function
def process(self):
start = time()
sleep(self.wait_)
print("process.duration:%s" % (time()-start))
return self
@timeout(.2)
def timedprocess(self):
self.process()
return self
try:
TimeItOut(.1).process().timedprocess()
TimeItOut(.3).process().timedprocess()
except (CustomTimeoutError,) as e: #pragma: no cover
print("caught you:%s" % (e))
I have a class like:
class A(object):
def init(self):
self.timeout=4
@timeout_decorator(self.timeout) # it dosn't work
def doanything(self):
print("do")
So, how to decorate doanything function in A class?
Thanks
The text was updated successfully, but these errors were encountered: