Catalog PyPI
PACKAGE EXPLORERView in registry

aioawait

PyPI

Call asynchronous functions of Python 3.4.3 asyncio infrastructure from synchronous code

Versions collected1
Direct dependencies0From release 8
Last observed21 Oct, 11:38 UTC

README

Version 8 documentation
aioawait
========

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. 
 
Installation
------------

.. code:: bash

    pip3 install aioawait

Example
-------

.. code:: python

    from asyncio.tasks import coroutine, sleep, async
    from aioawait import await, spawn
    
    @coroutine
    def monitor(name, size, total):
        while True:
            print('\ttotal', name, total)
            yield from sleep(1)
    
    @coroutine
    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)
            else:
                print('counting', name, n)
                yield
    
        # stops monitor
        m.cancel()
    
        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]))
    
        @property
        def counter_a(self):
            return await(counter('a', 20, [0]))
    
        @property
        def counter_b(self):
            return await(self.cb)
     
    if __name__ == '__main__':
        c = Counter()
        print(c.counter_a)
        print(c.counter_b)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
819 Mar 20150

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:38 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:6f8332042ca4bb2f913cab2b1702faa8bd4fbfe192548a83d29673d45b3d9c77