Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Call asynchronous functions of Python 3.4.3 asyncio infrastructure from synchronous code

Project Description

This package implements two primitives (await and spawn) on top of asyncio infrastructure of Python 3. This two functions allow us to call asynchronous functions from synchronous code.


pip3 install aioawait


from asyncio.tasks import coroutine, sleep, async
from aioawait import await, spawn

def monitor(name, size, total):
    while True:
        print('\ttotal', name, total)
        yield from sleep(1)

def counter(name, size, total):
    """sums into total all numbers from 0 to size"""
    m = async(monitor(name, size, total))

    # monitor could be called using spawn. eg:
    # m = spawn(monitor(name, size, total))

    for n in range(size):
        total[0] += n
        if n % 5 == 0:
            print('sleeping', name, n)
            yield from sleep(2)
            print('counting', name, n)

    # stops monitor

    return name, 'done', n, total

class Counter:
    """note that this class has no asynchronous code"""

    def __init__(self):
        self.cb = spawn(counter('b', 40, [0]))

    def counter_a(self):
        return await(counter('a', 20, [0]))

    def counter_b(self):
        return await(self.cb)

if __name__ == '__main__':
    c = Counter()

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(3.1 kB) Copy SHA256 Hash SHA256
Source None Mar 19, 2015

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting