prodcon
An easy to use implementation of the producer consumer pattern with threading
Installation
pip install prodcon
Example usage
import random
import time
from queue import Queue
from prodcon import Producer, Consumer
def generate_items(start, end):
for i in range(start, end + 1):
if i == end:
# Add poison pill to stop producer and consumers
yield None
# Simulate producing time
time.sleep(random.random())
print(f'Produced item #{i}')
yield f'Item #{i}'
def process_item(item):
# Simulate processing time
time.sleep(random.random() + 1)
print(f'Processed {item}')
q = Queue()
p = Producer(q, generate_items, args=(1, 100))
c = Consumer(q, process_item)
p.start()
c.start()
Example usage with decorators
import random
import time
from prodcon import produces, consumes
@produces
def generate_items(start, end):
for i in range(start, end + 1):
if i == end:
# Add poison pill to stop producer and consumers
yield None
# Simulate producing time
time.sleep(random.random())
print(f'Produced item #{i}')
yield f'Item #{i}'
@consumes
def process_item(item):
# Simulate processing time
time.sleep(random.random() + 1)
print(f'Processed {item}')
generate_items(1, 100)
# Use multiple consumers
for _ in range(5):
process_item()
Release files for prodcon 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prodcon-0.2.0.tar.gz | 2.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prodcon-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.8 kB
Release files / prodcon-0.2.0.tar.gz
| Download URL | prodcon-0.2.0.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74044f46448ab90a084fbb084d97cb187f0ad18fcb5cd86dd969aa0a49baa809
|
|
BLAKE2b-256 checksum How to use checksums |
a29497d91844b8b328b6a316b27a302a66b9f2a8495c009a346a5a1b6e8e9f5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4
|
Release files / prodcon-0.2.0-py3-none-any.whl
| Download URL | prodcon-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83229467668b4d3d1c1602a1c093858bf17960fd43a53a56a28b0bda017507df
|
|
BLAKE2b-256 checksum How to use checksums |
905500ce797270c252cab49c1849cb88a57fc6fb46b1b2478e9f13c47574bf0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4
|