Python Queue module and pythonqueue Module
Create a "queue" Object
Import Queue
Myqueue = Queue. Queue (maxsize = 10)
The Queue. Queue class is the synchronization implementation of a Queue. The queue length can be unlimited or limited. You can set the Queue length through the optional parameter maxsize of the Queue constructor. If maxsize is smaller than 1, the queue length is infinite.
Put a value into the queue
Myqueue. put (10)
Call the put () method of the queue object to insert a project at the end of the team. Put () has two parameters. The first item is required and is the value of the inserted project. The second block is an optional parameter. The default value is 1. If the queue is empty and the block is 1, The put () method suspends the calling thread until a data unit is empty. If the block is 0, the put method will cause a Full exception.
Extract A value from the queue
Myqueue. get ()
Call the get () method of the queue object to delete the queue header and return a project. The optional parameter is block. The default value is True. If the queue is empty and the block is True, get () will suspend the calling thread until a project is available. If the queue is Empty and the block is False, the queue will cause an Empty exception.
The python queue module has three Queues:
1. The first-in-first-out queue of the python queue module.
2. LIFO is similar to heap. That is, advanced and later.
3. The lower the priority queue level, the more advanced it is.
There are three constructor functions for these three Queues:
1. class Queue. Queue (maxsize) FIFO
2. class Queue. LifoQueue (maxsize) LIFO
3. class Queue. PriorityQueue (maxsize) priority Queue
Describes the common methods in this package:
Queue. qsize () returns the size of the Queue
Queue. empty () if the Queue is empty, True is returned. Otherwise, False is returned.
Queue. full () if the Queue is full, True is returned. Otherwise, False is returned.
Queue. full corresponds to maxsize
Queue. get ([block [, timeout]) get the Queue, timeout wait time
Queue. get_nowait () is equivalent to Queue. get (False)
Non-blocking Queue. put (item) Write Queue, timeout wait time
Queue. put_nowait (item) is equivalent to Queue. put (item, False)
After Queue. task_done () completes a job, the Queue. task_done () function sends a signal to the completed Queue of the job.
Queue. join () actually means that when the Queue is empty, other operations will be performed.