Limits the number of values generated by an iterator until acknowledged.
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file bounded_iterator-0.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: bounded_iterator-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed6976acaf3a38dc5de7e0f1ba1f26a9a621cb81f9d431f59a23f0b98e4fe51d |
|
MD5 | 81f422a8554ca82f722c8cbcc01c2c5f |
|
BLAKE2b-256 | 2eec573e7006c85edab939c2af380efdd69c5fcef23690d405609d4e3e3036a5 |