PriorityQueue python thread queue (Priority Queue) (37)

   

    In the  thread queue Queue  /  thread queue LifoQueue  article introduced the FIFO queue Queue out and the advanced queue LifoQueue, and today to tell you that last: a priority queue PriorityQueue, sort the data according to the priority queue, so specifically how to use it?

 

A queue Queue Category:

    1. thread queue Queue - FIFO (First In First Out queue), ie, which data is first stored, the time taken to fetch data which data, buy things with life line;

    2. Thread the queue LifoQueue - LIFO (last-out queue), that is, the last stored data which, when taken in the first data take the same life magazine pistol, bullets and finally into the first play;

    3. thread queue PriorityQueue - PriorityQueue (priority queue), i.e., when the added data is stored in a priority, when the highest priority of access to data extraction;

 

II. Introduction priority queue PriorityQueue

    Set the priority at the time the data is stored, the time taken in accordance with the data of the default highest priority out, Note: Use the priority data stored fetch data, the data queue must be of the same type, give chestnuts: Class standings / Height rank ......

    It is noted that: when the data stored in the priority queue PriorityQueue, the smaller the value, the higher the priority;

 

III. PriorityQueue priority queue function introduction

    Function not introduce too much, already in  the thread queue Queue  with detailed explanations, both of which belong to the Queue, functions are the same!

 

 

IV. PriorityQueue use priority queue

    Priority: whether numbers, letters, lists, and other tuples (dictionaries, set did not test), using the data stored in the priority access to data, data queue must be of the same type, ascii code table are in accordance with actual data order of priority matching, in accordance with the unicode characters table.

    Output:

[1, 'ace']
[ 3, ' Department ' ]
[5, '4asdg']
[40, 333]
ta
he
you
she was
I

 

    Thus: When the data stored in the priority queue PriorityQueue, the smaller the value, the higher the priority!

 

 

you may also like:

    1.python thread queue Queue-FIFO

    2.python thread queue LifoQueue

    3.python thread mutex Lock

    4.python thread time Event

 

    Reproduced please specify: ape say Python  »  Python thread queue PriorityQueue (priority queue)

 

Technical exchanges, business cooperation please contact bloggers
Scan code or search: ape say python
No public python tutorial
Ape say python
No. sweep the micro-channel public concern

Guess you like

Origin www.cnblogs.com/shuopython/p/11988627.html