DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Using Ao_timer For A Better Sleep

02.01.2006
| 8605 views |
  • submit to reddit
        A few of my old examples include 'unsafe' use of e32.ao_sleep().
The problem is that the sleep can't be interrupted.
I often use a convenient loop like this
while running:
  // do something
  e32.ao_sleep(1)  # sleep a sec

Now in pys60 1.3.1, it's better to use e32.Ao_timer
timer = e32.Ao_timer()
while running:
  // do something
  timer.after(1)   # sleep a sec
I can then interupt the sleep with 
timer.cancel()
in other part of the program if I need to continue the loop.

For example, I can end the application without waiting for
the last second.