Prefetch elements from a Python generator in the background, from a separate process
Project description
A library to prefetch items from a Python generator in the background, using a separate process.
Install (no dependencies):
pip install multiprocessing_generator
Example:
from multiprocessing_generator import ParallelGenerator def my_generator(): while True: # ... download something long ... yield result with ParallelGenerator( my_generator(), max_lookahead=100) as g: for elem in g: # ... do some heavy processing on that element ...
Up to 100 elements ahead of what is consumed will be fetched by the generator in the background, which is useful when the producer and the consumer do not use the same resources (for instance network vs. CPU).
The generator handles exceptions and more serious failures transparently.
Released under the MIT license.
See also: https://github.com/justheuristic/prefetch_generator
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
File details
Details for the file multiprocessing-generator-0.3.tar.gz
.
File metadata
- Download URL: multiprocessing-generator-0.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 778895fd84f2ce8c7bb5420500e885c87a6b4092f65af6d079f9482696d93175 |
|
MD5 | a3332ee6d3707c3718ca89653d15deb8 |
|
BLAKE2b-256 | 5bb10c5a75bf2113101addd86a93aadc40a87c3807288f7c055523f3023403f3 |