In Python's time module, there is a
Something like this:
while not x: time.sleep(0.1)
will wait until
x is true, sleeping a tenth of a second between checks. This is usually short enough for your script to seem to react instantly (in human terms) when
x becomes true. You could use
0.01 instead if this is not quick enough. In my experience, today's computers are fast enough that checking a simple condition even every hundredth of a second doesn't really make a dent in CPU usage.
x should be something that can actually change, e.g. a function call.