Over a million developers have joined DZone.

Using Ao_sleep

·
In python for series 60, the use of e32.ao_sleep is encourage
over time.sleep. AO stands for 'Active Object' approach to
cooperative multi-tasking. When an object go to 'ao_sleep'
other active objects can run.

import e32
e32.ao_sleep(5)  # sleep for 5 seconds

There is another usage ao_sleep(interval, callback)
where ao_sleep will return immediately but the callback
will be called after the interval (in another thread?)

This could be used to create a repeat loop for every interval.
I show this in a previous snippet.

import e32, time

def showtime():
  print time.clock()
  e32.ao_sleep(1, showtime)  # sleep then call itself again

showtime()  # start the loop
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}