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.2.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

prodcon-0.1.2-py3-none-any.whl (15.1 kB view hashes)

Uploaded Python 3

Supported by

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