Notifications on encoder changes

When programming a GoPiGo, in Python or Scratch, the pattern for making the robot go forward a distance seems to be something like this:


… some kind of sleep loop: currently I use something like:

while read_enc_status() != 0:

I feel like this is a pretty terrible programming pattern, and not something that I’d want to teach a young programmer. Is there a method which can wait until the encoder value changes? For instance, using select.poll() on a file descriptor or select.epoll somehow? With an accurate wait function, you could at least write a non-laggy synchronous wait loop, but you could also start doing asynchronous programming and react to encoder changes as necessary.