Skip to main content

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

pip3 install aioawait

Example

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)

Metadata

Release files for aioawait 3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aioawait 3
File Size Uploaded Provenance Actions
aioawait-3.tar.gz 2.9 kB Without provenance Details for aioawait-3.tar.gz

Release files / aioawait-3.tar.gz

Download URL aioawait-3.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
65dd7d6554904fdf84613788655bec89af840d9ff6ad8bdb2b9085e52c7e70e8
BLAKE2b-256 checksum
How to use checksums
15c9b40b368740e9dbf21506052631d6d03d66896169da5b92d7b4c289d1a9f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for aioawait 3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page