Skip to main content

Multi consumers asyncio compatible queue

Project description

A simple multi-consumer asyncio compatible queue. The below

import asyncio
from mpmc import Broadcast


async def print_stream(stream, name: str, delay: float):
    async for i in stream:
        await asyncio.sleep(delay)
        print(name, i)


async def feed_stream(nb_values: int, live_stream: Broadcast[int]):
    for i in range(nb_values):
        await asyncio.sleep(0.2)
        live_stream.put(i)
    live_stream.close()


async def main():
    source_stream = Broadcast()
    await asyncio.gather(
        feed_stream(5, source_stream),
        print_stream(source_stream, "fast", 0.5),
        print_stream(source_stream, "slow", 1),
    )

asyncio.run(main())

will produce:

fast 0
slow 0
fast 1
slow 1
fast 2
fast 3
slow 2
fast 4
slow 3
slow 4

Project details


Download files

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

Source Distribution

aio_broadcast-1.0.1.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aio_broadcast-1.0.1-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file aio_broadcast-1.0.1.tar.gz.

File metadata

  • Download URL: aio_broadcast-1.0.1.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aio_broadcast-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9eebaff291c806c08f04ab7770c18eaec1a3c7efa390c16b7d09b95885ad0c15
MD5 f301eec7d2a94e88a3d7528e4a24ec30
BLAKE2b-256 6bdf648dbf7e918bae558101eb55b9577e6bef5b888702e684388f468a1231db

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_broadcast-1.0.1.tar.gz:

Publisher: ci.yml on pytek-io/aio-broadcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aio_broadcast-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aio_broadcast-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aio_broadcast-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e1791ba187807fdec94f970c2ba70869b5e3846bff800e21075eae48f6dad525
MD5 cc526fb5ba7dc1ed1008f4fe2f21fafa
BLAKE2b-256 ea190c017541a0e937669e5689b15d47e3ab54aae9d79950165a9ff4bae1473b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_broadcast-1.0.1-py3-none-any.whl:

Publisher: ci.yml on pytek-io/aio-broadcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page