queue
modules
/queue module
1 Constants /Constants
Pass
2 function /Function
Pass
3 class /Class
3.1 Queue class
class Instantiation: Queue = queue. Queue(maxsize=0)
functions of the class : used to generate a first-in, first-out queue instance
Incoming Parameters : MaxSize
Maxsize:int type, maximum queue size, blocked when no space is specified, infinite queue when unspecified
return Parameters : Queue
Queue:instance type, generated first-in, first-out queue instance
3.1.1 put () Method
function Call : Queue.put (item, Block=true, Timeout=none)
function function : put item in the queue
Incoming Parameters : Item, block, timeout
Item:int/str/obj, etc. type, put into the queue of items
Block:bool type, set block, True is blocked, false throws an exception
Timeout:none/int type, set blocking time-out (s), None is blocked indefinitely
return Parameters : No
3.1.2 Get () Method
function Call : item = Queue.get (Block=true, Timeout=none)
function function : Remove the item from the queue
Incoming Parameters : block, timeout
Block:bool type, set block, True is blocked, false throws an exception
Timeout:none/int type, set blocking time-out (s), None is blocked indefinitely
return Parameters : Item
Item:int/str/obj types, items removed from the queue
3.1.3 put_nowait () Method
function Call : Queue.put_nowait (item)
function function : No wait to put item in queue, equivalent to put (item, False), failure throws full exception
Incoming Parameters : Item
Item:int/str/obj, etc. type, put into the queue of items
return Parameters : No
3.1.4 get_nowait () Method
function Call : item = queue.get_nowait ()
function function : No wait for the item to be fetched from the queue, equivalent to get (False), and failure throws an empty exception
Incoming Parameters : No
return Parameters : Item
Item:int/str/obj and other types, items removed from the queue
3.1.5 Task_done () Method
function Call : Queue.task_done ()
function function : used to indicate that a task has been completed, set the completion flag, often used for queue consumption threads, each get () function takes out an item, and can then set a task_done, when all queue tasks are marked complete, join will release blocking
Incoming Parameters : No
return Parameters : No
3.1.6 Join () Method
function Call : Queue.join ()
function function : used to block the current thread until all queues (including tasks before join into row and dequeue) are set with the Task_done flag before the join IS unblocked
Incoming Parameters : No
return Parameters : No
3.1.7 qsize () Method
function Call : size = queue.qsize ()
function function : Returns the size of the current queue (the value is not accurate, approximate, due to changes in other threads)
Incoming Parameters : No
return Parameters : Size
Siez:int type, number of item in queue
3.1.8 Empty () Method
function Call : status = Queue.empty ()
function function : Returns the status of the current queue, returns true for NULL, otherwise returns false, as with Qsize, returns an approximation, and if it is necessary to wait for all queues to end, the join () function is recommended
Incoming Parameters : No
return Parameters : Status
Status:bool type, true indicates that the current queue is empty
3.1.9 Full () Method
function Call : status = Queue.full ()
function function : Returns the status of the current queue, returns True if the queue is full, otherwise returns false, and returns an approximate value
Incoming Parameters : No
return Parameters : Status
Status:bool type, true indicates that the current queue is empty
3.2 Lifoqueue class
class Instantiation: Queue = queue. Lifoqueue(maxsize=0)
functions of the class : used to generate a back-in, first-out queue instance
Incoming Parameters : MaxSize
Maxsize:int type, maximum queue size, blocked when no space is specified, infinite queue when unspecified
return Parameters : Queue
Queue:instance type, generated after-first-out queue instance
Note:
For the Lifoqueue class, the base class is the queue, where the queue's _init, _qsize, _put, _get functions are redefined in the source code so that they differ in the order in which the queues are processed (the essence is _get () when the item is fetched to the queue list) function uses either the Popleft function or the pop function, and the function of its parent class can be inherited.
3.3 Priorityqueue class
class Instantiation: Queue = queue. Priorityqueue(maxsize=0)
functions of the class : used to generate a priority queue instance with the smallest optimal pull-out
Incoming Parameters : MaxSize
Maxsize:int type, maximum queue size, blocked when no space is specified, infinite queue when unspecified
return Parameters : Queue
Queue:instance type, generated priority queue instance
Note:
For the Priorityqueue class, the base class is also the queue, which also redefined the queue's _init, _qsize, _put, _get functions in the source code, making it different in the queue's processing order (the essence is _get () when the item is fetched to the queue list) The Heappop function is used, and the Heappush function is used when it is placed, and the parent function can also be used for inheritance.
3.4 Empty Exception Class
class Instantiation: No
functions of the class : for exceptions thrown when the queue is empty and the get* () method is called
Incoming Parameters : No
return Parameters : No
3.5 Full Exception Class
class Instantiation: No
functions of the class : for exceptions thrown when the queue is full and the put* () method is called
Incoming Parameters : No
return Parameters : No
Python queue module for concurrent parallel [2], queues