I'm sure this is somewhat common, so I'm curious what are the acceptable / effective ways to do this in Python.
Simply put, I'm just busy waiting for a variable to update. At the same time, I need a timeout scheme, but I believe that there should be a better way to do this.
I am currently doing something like this:
wait_start = time.time()
while state != NEW_STATE:
if time.time() - wait_start > timeout:
print "Timed out!"
I obviously just can't sleep because I need to know when the condition has changed.
So, what is an effective method to implement a timeout to change state (variable)?
source
share