Programs developed with asyncoro have same logic and structure as programs with threads, except for a few syntactic changes - mostly using yield with asynchronous completions that give control to asyncoro’s scheduler, which interleaves executions of coroutines, similar to the way an operating system executes multiple processes.
Unlike threads, creating processes (coroutines) with asyncoro is very efficient. For reference purposes, asyncoro with Python 2.7 on Ubuntu Linux 12.04 running the concurrent program:
import asyncoro, resource, time def coro_proc(coro=None): yield coro.suspend() coros = [asyncoro.Coro(coro_proc) for i in xrange(100000)] time.sleep(5) ru = resource.getrusage(resource.RUSAGE_SELF) print('Max RSS: %.1f MB' % (ru.ru_maxrss / 1024.0)) for coro in coros: coro.resume()
shows that 100,000 coroutines take about 200 MB of resident memory (RSS field). Moreover, with asyncoro context switch occurs only when coroutines use yield (typically with an asychronous call), so there is no need for locking and there is no overhead of unnecessary context switches.
asyncoro can be downloaded from Sourceforge Files. It is released under MIT license, a common license used for Python modules. Files asyncoro.py, disasyncoro.py etc. in asyncoro-* are to be used with Python 2.7+ and files asyncoro3.py, disasyncoro3.py etc. in asyncoro3-* are to be used with Python 3.1+. If using Python 3.1+ exclusively, asyncoro3.py may be renamed to asyncoro.py etc.