Skip to main content

An easy to use implementation of the producer consumer pattern

Project description

prodcon

An easy to use implementation of the producer consumer pattern

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}')


def main():
    q = Queue()
    p = Producer(q, generate_items, args=(1, 100))
    c = Consumer(q, process_item)

    p.start()
    c.start()


if __name__ == '__main__':
    main()

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

prodcon-0.1.0.tar.gz (1.4 kB view details)

Uploaded Source

Built Distribution

prodcon-0.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file prodcon-0.1.0.tar.gz.

File metadata

  • Download URL: prodcon-0.1.0.tar.gz
  • Upload date:
  • Size: 1.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for prodcon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b51d630963d16da972325cba889114939b248aca03e98ccb2cc7db17b3c29e6f
MD5 c9637d5bc09c8321b5fc5046d897baeb
BLAKE2b-256 5fe9ee180a3187a45eea6caa722e7d27d9ceb16c7868d3520477168bba3c8b99

See more details on using hashes here.

File details

Details for the file prodcon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: prodcon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for prodcon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76bd675ad2cd45f71a57a549dfced7fddfcfcc99db20adbd4bf99749759152e2
MD5 f463de9e62a0fe6e7a75fe0fb93df0d4
BLAKE2b-256 e130d894e949ad012df97ee62a68566cd0baccbef26578f0aa5a276d492ba245

See more details on using hashes here.

Supported by

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