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.

Release files for concurrent-iterator 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for concurrent-iterator 0.4.0
File Size Uploaded
concurrent_iterator-0.4.0.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for concurrent-iterator 0.4.0
File Interpreter ABI Platform
concurrent_iterator-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / concurrent_iterator-0.4.0.tar.gz

Download URL concurrent_iterator-0.4.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1867853a07779b9f73d1c4b3b8ce2d3277b2234fac6a7cb2cf5562d269fa64e8
BLAKE2b-256 checksum
How to use checksums
69040957f0f1fdd94fb524a0607ee27bdb82c0e0884752f310204cfaf6c0dac5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.7

Release files / concurrent_iterator-0.4.0-py3-none-any.whl

Download URL concurrent_iterator-0.4.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0748a2d5c578b153315cf42d0f4b929e55bc71ff3c125af1e2a724a95bcc307d
BLAKE2b-256 checksum
How to use checksums
25e634fb4cabaca8eb73bcc51b88adcf880850f95e1451ca1df1769dd696ccbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

0.1

2 release 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