bounded-iterator
Intro
multiprocessing.pool.ThreadPool and multiprocessing.Pool have the wonderful imap and imap_unordered methods which allow to consume an iterable incrementally and will yield results as they become available.
This is wonderful as it allows to process inputs or results larger than available memory.
It has an important flaw which is that it does not limit the number of results that are not consumed. This causes it to use memory without bound.
This package implements a wrapper over an iterable which will limit the number of results generated until they are acknowledged. It allows a number of messages to be processed concurrently but no more than that.
Usage
it = itertools.count() # The input iterable.
it = BoundedIterator(10, it) # Allows concurrent processing of up to 10 values.
results = Pool().imap(str, it) # Will begin consuming `it` and producing results.
time.sleep(5) # No matter what else we do, no more than 10 results will be available.
for res in results: # Consume normally.
print(res)
it.processed() # Acknowledge a value was processed so that a new one can be generated.
Development
Setup pre-commit hooks and you are ready to go.
pre-commit install --install-hooks
Metadata
Release files for bounded-iterator 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bounded_iterator-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Release files / bounded_iterator-1.0.2-py3-none-any.whl
| Download URL | bounded_iterator-1.0.2-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce965e17ce5445bb9137715c7ec63b0829d8bf5f887c7ee5b259b806045d0592
|
|
BLAKE2b-256 checksum How to use checksums |
5e5197197017e6e3f9ef3a73cad430311e594d160a598193d7f7d96d1b702344
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.4
|
Security for bounded-iterator 1.0.2
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.