Queue description
Processes are isolated from each other, and to implement interprocess communication (IPC), the Multiprocessing module supports two forms: queues and pipelines, both of which use message passing
Create a queue class (the underlying is implemented as a pipe and lock)
Queue (MAXSIZE): Creates a shared process queue, which is a multi-process secure queue that enables data transfer between multiple processes using queue
Parameter introduction
MaxSize is the maximum number of items allowed in the queue, omitted without a size limit but needs to be clear: 1, the queue is stored in the message rather than the big Data 2, the queue occupies the memory space, so maxsize even if no size limit is limited by the memory size
Introduction to the main methods
The Q.put method is used to insert data into the queue Q.get method can read from the queue and delete an element
Use of queues
From multiprocessing Import Queueq = Queue (3) q.put (1) q.put (2) q.put (3) print (Q.full ()) # full # q.put (4) # It's jammed again. Print (Q.get ()) print (Q.get ()) print (Q.get ()) print (Q.empty ()) # Empty print (Q.get ()) # and then it's jammed.
Python concurrent Programming: Multi-process-queue