Stdbuf
Size and time bounded asynchronous buffer with deduplication.
Buffer's content is flushed when either maximum size or time since the first insertion reaches the specified limits.
Inspired by ClickHouse buffer engine. Used for the same purpose.
Note
Multiple concurrent consumers are not supported.
Usage
import asyncio
import time
from stdbuf import Stdbuf
async def produce(buf: Stdbuf[int]):
for i in range(2 ** 16):
await buf.put(i)
# Duplicates are ignored.
await buf.put(i)
async def consume(buf: Stdbuf[int]):
while True:
start = time.perf_counter()
# Get data at least every 2 seconds.
# May return earlier if full.
data = await buf.get()
elapsed = time.perf_counter() - start
assert len(data) <= 16
assert elapsed <= 0.5 + 1e-2
async def main():
with Stdbuf(16, 0.5, True) as buf:
done, pending = await asyncio.wait({
asyncio.create_task(produce(buf)),
asyncio.create_task(consume(buf)),
},
return_when=asyncio.FIRST_COMPLETED,
)
for task in pending:
task.cancel()
if __name__ == "__main__":
asyncio.run(main())
Metadata
Release files for stdbuf 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stdbuf-1.1.0.tar.gz | 4.6 kB | Without provenance | Details for stdbuf-1.1.0.tar.gz |
Release files / stdbuf-1.1.0.tar.gz
| Download URL | stdbuf-1.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
757badb395af826fe9c31c08a9e1fcfb866dee744d335d36b12973b2369efe4b
|
|
BLAKE2b-256 checksum How to use checksums |
015b757c0fbf21e4e00275e747473f1c3aa66cac53f11a05b23135894ccf2656
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Linux/5.13.0-1021-azure
|
Security for stdbuf 1.1.0
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.