9

I wrote a polling function to check the value of reg_result variable for 120 seconds.

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)

Is there any other better way of writing a polling method?

Is it possible by not using a while loop?

1 Answer 1

14

There is a library in python Polling(https://pypi.python.org/pypi/polling/0.3.0) You can use this

from polling import TimeoutException, poll
try:
    poll(lambda: reg_result=='REGISTERED', timeout=120, step=1)
except TimeoutException as tee:
    print "Value was not registered"

Hope it helps.

Sign up to request clarification or add additional context in comments.

3 Comments

This prints the Value no matter wether exception is faced or not. It will wait to do the polling but in the end will run the print statement either way.
There is now a better alternative: see pypi.org/project/polling2
@TimDowty this project is just as broken as the original.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.