The development of parallel applications has the need for the exchange of data between processes. The multiprocessing library has two communication channels with which it can manage the exchange of objects: queues and pipes.
A queue returns a process shared queue, is thread and process safe, and any serializable object (Python serializes an object using the pickable module) can be exchanged through it.
In the following example, we show you how to use a queue for a producer-consumer problem. The
producer class creates the item and queues and then, the
consumer class provides the facility to remove the inserted item:
import multiprocessing import random import time class producer(multiprocessing.Process): def __init__(self, queue): multiprocessing.Process.__init__...