Skip to main content

Prefetch elements from a Python generator in the background, from a separate process

Project description

Build Status PyPI

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multiprocessing-generator-0.1.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file multiprocessing-generator-0.1.tar.gz.

File metadata

File hashes

Hashes for multiprocessing-generator-0.1.tar.gz
Algorithm Hash digest
SHA256 7fdf94216d9efc2b2907ecbb762e9a0c7964a9e610018f4a0530e72325592aee
MD5 2c806b8fcdcc6ff4ceb493db1735a9cc
BLAKE2b-256 9c8c59858762ce7de155fd4ca00dab2db45401bd86840382adf0c5edcc303b22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page