Skip to main content

Multithreating producent-consumer solution

Project description

queuing

Multithreating producent-consumer solution

Example

import queuing
import time
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(levelname)5s] %(name)s %(message)s')


@queuing.consumer(instances=5)
def m1(no):
    time.sleep(1)
    print("m1 {}".format(no))
    queuing.broker.send('m2', {
        'no': no,
        'sqno': no * no,
    })
    [queuing.broker.send('m3', {
        'no': no,
    }) for i in range(0, 10)]


@queuing.consumer(instances=2)
def m2(no, sqno):
    time.sleep(2)
    print("m2 {} {}".format(no, sqno))


@queuing.consumer(instances=1)
def m3(no):
    print("m3 {}".format(no))


if __name__ == '__main__':
    for i in range(0, 10):
        queuing.broker.send('m1', {
            'no': i
        })

    queuing.broker.loop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for queuing, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size queuing-0.3.1-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size queuing-0.3.1.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page