我写了一个轮询函数来检查reg_result
变量的值120秒.
reg_result = 0 while_timeout = time.time() + 120 while reg_result is not "REGISTERED" and time.time() < while_timeout: reg_result = LeshanObj.validate_reg_time(parameter_1)
有没有其他更好的方法来编写轮询方法?
是不是可以通过while
循环?
python Polling中有一个库(https://pypi.python.org/pypi/polling/0.3.0)你可以用它
from polling import TimeoutException, poll try: poll(lambda: reg_result=='REGISTERED', timeout=120, step=1) except TimeOutException as tee: print "Value was not registered"
希望能帮助到你.