Skip to Content
Distributed Computing with Python
book

Distributed Computing with Python

by Francesco Pierfederici
April 2016
Intermediate to advanced
170 pages
3h 48m
English
Packt Publishing
Content preview from Distributed Computing with Python

Multiprocess queues

When using multiple processes, the issue that comes up is how to exchange data between the workers. The multiprocessing module offers a mechanism to do that in the form of queues and pipes. Hence, we are going to look at multiprocess queues.

The multiprocessing.Queue class is modeled after the queue.Queue class with the additional twist that items stored in the multiprocessing queue need to be pickable. To illustrate how to use these queues, create a new Python script (queues.py) with the following code:

import multiprocessing as mp


def fib(n):
    if n <= 2:
        return 1
    elif n == 0:
        return 0
    elif n < 0:
        raise Exception('fib(n) is undefined for n < 0')
    return fib(n - 1) + fib(n - 2)


def worker(inq, outq):
    while True:
 data ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Distributed Machine Learning with Python

Distributed Machine Learning with Python

Guanhua Wang
Scientific Computing with Python - Second Edition

Scientific Computing with Python - Second Edition

Claus Führer, Claus Fuhrer, Jan Erik Solem, Olivier Verdier
Learning Python Networking - Second Edition

Learning Python Networking - Second Edition

José Manuel Ortega, Dr. M. O. Faruque Sarker, Sam Washington

Publisher Resources

ISBN: 9781785889691Supplemental Content