Over a million developers have joined DZone.

Using Ao_sleep

DZone's Guide to

Using Ao_sleep

Free Resource
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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}