Skip to main content

concurrent-iterator

Supported Python versions License

Intro

Classes to run producers (iterators) and consumers (coroutines) in a background thread/process.

There are many libraries to create pipelines with stages running in separate processes, a nice one is parallelpipe, but this library does something different. It will lift the entire pipeline up to the point of the Producer into a separate process or thread. It's a more coarse library but easier to integrate since things keep looking as normal generators.

Implementations

There are currently 3 implementations:

  • dummy.Producer: non-concurrent implementation
  • thread.Producer: uses a background thread to run the generator
  • process.Producer: uses a background process to run the generator

dummy.Producer is useless in practice.

thread.Producer is useful for IO bound generators.

process.Producer is useful for CPU or IO bound generators. It has the complications of dealing with processes (different memory spaces, logging, etc). For logging, module multiprocessing-logging can be used.

Limitations: process.Producer/process.Consumer with generators, coroutines and other unpicklable objects require the fork start method. Python 3.14 changes the default on Linux from fork to forkserver, and spawn/forkserver cannot pickle generators (TypeError: cannot pickle 'generator' object). In those cases process.Producer now raises RuntimeError with a clear message. Use thread.Producer/thread.Consumer, a picklable iterable (e.g. iter([1,2,3])), or force fork via multiprocessing.set_start_method('fork', force=True) or multiprocessing.get_context('fork').Process/Queue where fork is available (Linux).

Usage

Basic example:

from concurrent_iterator.thread import Producer

...

items = Producer(slow_generator, maxsize=5)

for item in items:
    [Do some time consuming task]

In the previous example, while doing some time consuming task, the slow_generator will continue running in a background thread and will pre-calculate up to 5 values.

Download files

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

Source Distribution

concurrent_iterator-0.4.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

concurrent_iterator-0.4.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file concurrent_iterator-0.4.0.tar.gz.

File metadata

  • Download URL: concurrent_iterator-0.4.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.7

File hashes

Hashes for concurrent_iterator-0.4.0.tar.gz
Algorithm Hash digest
SHA256 1867853a07779b9f73d1c4b3b8ce2d3277b2234fac6a7cb2cf5562d269fa64e8
MD5 4aa6371b15f1900fd56a88b53e4c4a37
BLAKE2b-256 69040957f0f1fdd94fb524a0607ee27bdb82c0e0884752f310204cfaf6c0dac5

See more details on using hashes here.

File details

Details for the file concurrent_iterator-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for concurrent_iterator-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0748a2d5c578b153315cf42d0f4b929e55bc71ff3c125af1e2a724a95bcc307d
MD5 96317f201244a3c9d607e4cad50514cc
BLAKE2b-256 25e634fb4cabaca8eb73bcc51b88adcf880850f95e1451ca1df1769dd696ccbb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.0

1 file

0.2.6

1 file

0.2.5

1 file

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2

2 files

0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page