Multi consumers asyncio compatible queue
Project description
This library enables concurrent iteration over the same stream of values asynchronously. This can be achieved by either creating a Queue that can be iterated simultanously from multiple consumers or wrapping an async generator to make it also iterable simultaously.
Below is an example of MultiQueue use.
import asyncio
from aio_broadcast import MultiQueue
async def print_stream(stream, name, delay):
async for i in stream:
await asyncio.sleep(delay)
print(name, i)
async def main():
stream = MultiQueue()
consumers = [asyncio.create_task(print_stream(stream, f"consumer {i}", 1 / (i + 1))) for i in range(5)]
for i in range(5):
await asyncio.sleep(0.2)
stream.put(i)
stream.close()
await asyncio.gather(*consumers)
asyncio.run(main())
An async generator can be iterated through simultanously as follows.
import asyncio
from aio_broadcast import broadcast
import random
random.seed(0)
async def consume_stream(stream, name):
async for value in stream:
await asyncio.sleep(random.uniform(0, 0.1))
print(name, value)
async def stream(values):
for value in values:
await asyncio.sleep(random.uniform(0, 0.5))
yield value
async def main():
values = list(range(5))
source_stream = broadcast(stream(values))
await asyncio.gather(
*[consume_stream(source_stream) for _ in range(3)],
)
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aio_broadcast-1.0.3.tar.gz.
File metadata
- Download URL: aio_broadcast-1.0.3.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce61b913f23f8a788678ef23570b565973899300fadb3c4585719b9a84bd9f3b
|
|
| MD5 |
810ab95790fe601110d019f8efb1ef1a
|
|
| BLAKE2b-256 |
2cc0ca89a231ccbe3189d742b2827a29be7bf8260e79367fbab5da2f3a30fe66
|
Provenance
The following attestation bundles were made for aio_broadcast-1.0.3.tar.gz:
Publisher:
ci.yml on pytek-io/aio-broadcast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aio_broadcast-1.0.3.tar.gz -
Subject digest:
ce61b913f23f8a788678ef23570b565973899300fadb3c4585719b9a84bd9f3b - Sigstore transparency entry: 181826022
- Sigstore integration time:
-
Permalink:
pytek-io/aio-broadcast@eb02080039e51b3c9ddd12f1a907a0ffc3d7e4b7 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/pytek-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@eb02080039e51b3c9ddd12f1a907a0ffc3d7e4b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aio_broadcast-1.0.3-py3-none-any.whl.
File metadata
- Download URL: aio_broadcast-1.0.3-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3286d4ea944202cb7a23f8319c5e22820c8581315c5e1b767f884354e00e2974
|
|
| MD5 |
362f0f9433968f9c2c5637d5f6bde8e5
|
|
| BLAKE2b-256 |
7561ed5286564d5ab3790b216ae57027c4c7bd87d3c7db0c24aa27514fb2aa9b
|
Provenance
The following attestation bundles were made for aio_broadcast-1.0.3-py3-none-any.whl:
Publisher:
ci.yml on pytek-io/aio-broadcast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aio_broadcast-1.0.3-py3-none-any.whl -
Subject digest:
3286d4ea944202cb7a23f8319c5e22820c8581315c5e1b767f884354e00e2974 - Sigstore transparency entry: 181826024
- Sigstore integration time:
-
Permalink:
pytek-io/aio-broadcast@eb02080039e51b3c9ddd12f1a907a0ffc3d7e4b7 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/pytek-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@eb02080039e51b3c9ddd12f1a907a0ffc3d7e4b7 -
Trigger Event:
push
-
Statement type: