concurrent-iterator
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 implementationthread.Producer: uses a background thread to run the generatorprocess.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.Consumerwith generators, coroutines and other unpicklable objects require theforkstart method. Python 3.14 changes the default on Linux fromforktoforkserver, andspawn/forkservercannot pickle generators (TypeError: cannot pickle 'generator' object). In those casesprocess.Producernow raisesRuntimeErrorwith a clear message. Usethread.Producer/thread.Consumer, a picklable iterable (e.g.iter([1,2,3])), or forceforkviamultiprocessing.set_start_method('fork', force=True)ormultiprocessing.get_context('fork').Process/Queuewhereforkis 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1867853a07779b9f73d1c4b3b8ce2d3277b2234fac6a7cb2cf5562d269fa64e8
|
|
| MD5 |
4aa6371b15f1900fd56a88b53e4c4a37
|
|
| BLAKE2b-256 |
69040957f0f1fdd94fb524a0607ee27bdb82c0e0884752f310204cfaf6c0dac5
|
File details
Details for the file concurrent_iterator-0.4.0-py3-none-any.whl.
File metadata
- Download URL: concurrent_iterator-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0748a2d5c578b153315cf42d0f4b929e55bc71ff3c125af1e2a724a95bcc307d
|
|
| MD5 |
96317f201244a3c9d607e4cad50514cc
|
|
| BLAKE2b-256 |
25e634fb4cabaca8eb73bcc51b88adcf880850f95e1451ca1df1769dd696ccbb
|