def wait_x_seconds_decorator(wait_time_sec=100):
"""
Method "func" should return True or False
"""
def func_wrap(func):
"""
"""
def inner_wrap(*args, **kwargs):
wait_time = kwargs.get("wait_time_sec")
if not wait_time:
wait_time = wait_time_sec
st = time.time()
status = None
while True:
status = func(*args, **kwargs)
if status:
return True
tt = time.time() - st
if tt >= wait_time:
raise Exception("Timeout Error")
return inner_wrap
return func_wrap
Usage
=====
@wait_x_seconds_decorator()
def test_method(name, wait_time_sec=10):
"""
"""
##Do some thing
If done:
return True
return False
"""
Method "func" should return True or False
"""
def func_wrap(func):
"""
"""
def inner_wrap(*args, **kwargs):
wait_time = kwargs.get("wait_time_sec")
if not wait_time:
wait_time = wait_time_sec
st = time.time()
status = None
while True:
status = func(*args, **kwargs)
if status:
return True
tt = time.time() - st
if tt >= wait_time:
raise Exception("Timeout Error")
return inner_wrap
return func_wrap
Usage
=====
@wait_x_seconds_decorator()
def test_method(name, wait_time_sec=10):
"""
"""
##Do some thing
If done:
return True
return False
No comments:
Post a Comment