directory
- Python thread Queue classification
- Python PriorityQueue
- Python thread PriorityQueue
- Python thread PriorityQueue
- Five. Guess you like it
Recommended path for learning Python: Python Learning Directory >> Python Basics
LifoQueue: LifoQueue: LifoQueue: LifoQueue: LifoQueue: LifoQueue: LifoQueue: LifoQueue: LifoQueue: LifoQueue A PriorityQueue sorts data in a queue by priority.
Python thread Queue classification
- 1. Thread Queue — FIFO(first in, first out), that is, which data is stored first, which data is fetched first, the same as in life Queue to buy things;
- 2. Thread queue LifoQueue — LIFO(first in, last out queue), that is, which data is stored last, the data is taken first, similar to the pistol magazine in life, the last bullet into the first out;
- 3. PriorityQueue – PriorityQueue(PriorityQueue), that is, when data is stored, a priority is added to the queue, and when data is fetched, the queue with the highest priority is taken out;
Python PriorityQueue
Note: To use the priority storage data to retrieve data, the data in the queue must be of the same type, for example: class grade ranking/height ranking……
Note that when storing data to PriorityQueue, the smaller the value, the higher the priority;
Python thread PriorityQueue
I don’t want to talk too much about functions, we’ve already talked about thread queues, both belong to queues, and both functions are the same!
Python thread PriorityQueue
By priority: Whether it is numbers, letters, lists, tuples, etc. (dict and set are not tested), the data in the queue must be the same type, and the priority is matched according to the ASCII code table of the actual data. Chinese characters are matched according to the Unicode table.
#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python thread priorityqueue. py @time :2021/05/05 07:37 @Motto: A thousand miles without a small stream without a river. The wonderful program life needs to accumulate unremittingly! """ import queue import threading import time q = queue.PriorityQueue() q.put([1, 'ace']) q.put([40, 333]) q.put([3, 'afd']) q.put([5, '4asdg']) # 1 while not q.epty (): Print (q.net ()) q = queue.priorityQueue () q.put(' I ') q.put(' you ') q.put(' he ') q.put(' she ') q.put('ta') while not Q.e mpty () : print (q.g et () ' ' 'output: [1,' ace '] [3] 'afd' [5 '4 asdg] [40, 333] ta he you she me' ' 'Copy the code
** When storing data to PriorityQueue, the smaller the value, the higher the priority! 六四屠杀
Five.Guess you like
- Python conditional derivations
- Python list derivations
- Python dictionary derivations
- Python function declarations and calls
- Python variable argument *argc/**kargcs
- Python anonymous function lambda
- Python return logic determines expressions
- Python string/list/tuple/dictionary conversions
- Python local and global variables
- The Python type function is different from the isinstance function
- Python is differs from ==
- Python mutable and immutable data types
- Shallow and deep copies of Python
- Read and write Python files
- Python exception Handling
- Python module import
- Python __name__ == ‘__main__’ explained in detail
- Python thread creation and parameter passing
- Python thread mutex Lock
- Python thread time Event
- The Python thread Condition variable Condition
- Python thread Timer Timer
- Python thread Semaphore
- Python thread Barrier object Barrier
- Python thread Queue Queue – FIFO
- Python thread queue LifoQueue – LIFO
- Python thread PriorityQueue PriorityQueue
Python thread PriorityQueue PriorityQueue
This article is published by the blog – Ape Say Programming Ape Say programming!