Python Thread Programming (3) Synchronous queues We often use two threads of the producer / consumer relationship to handle data for shared buffers. For example, a producer thread accepts user data into a shared buffer, waiting for a consumer thread to take out data. However, if the buffer is too small and the speed of the producers and consumers does not appear, it is easy to wait for another situation. In order to shorten the shared resources and the waiting time for each thread working on the same speed, we can use a "queue" to provide additional buffers. Create a "queue" object import Queue myQueue = queue.Queue (maxsize = 10) Queue.Queue class is a queue synchronization implementation. The queue length can be unlimited or limited. The queue length can be set by an optional parameter maxSize of the constructor of Queue. If the maxSize is less than 1, it means that the queue length is unlimited. Put a value in the queue in the queue. Put () method inserts a queue object inserted into a project at the tail. Put () has two parameters, the first Item is required, inserted into the item value; the second block is an optional parameter, default is 1. If the queue is currently empty and the block is 1, the PUT () method is paused until a data unit is empty. If Block is 0, the PUT method will trigger a Full exception. Remove a value from the queue to the get () method to call the queue object from the team head and return a project. Optional parameters are block, default is 1. If the queue is empty and the block is 1, get () will cause the call thread to be paused until there is a project. If Block is 0, the queue will trigger EMPTY exception.