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

  1. Python conditional derivations
  2. Python list derivations
  3. Python dictionary derivations
  4. Python function declarations and calls
  5. Python variable argument *argc/**kargcs
  6. Python anonymous function lambda
  7. Python return logic determines expressions
  8. Python string/list/tuple/dictionary conversions
  9. Python local and global variables
  10. The Python type function is different from the isinstance function
  11. Python is differs from ==
  12. Python mutable and immutable data types
  13. Shallow and deep copies of Python
  14. Read and write Python files
  15. Python exception Handling
  16. Python module import
  17. Python __name__ == ‘__main__’ explained in detail
  18. Python thread creation and parameter passing
  19. Python thread mutex Lock
  20. Python thread time Event
  21. The Python thread Condition variable Condition
  22. Python thread Timer Timer
  23. Python thread Semaphore
  24. Python thread Barrier object Barrier
  25. Python thread Queue Queue – FIFO
  26. Python thread queue LifoQueue – LIFO
  27. Python thread PriorityQueue PriorityQueue

Python thread PriorityQueue PriorityQueue

This article is published by the blog – Ape Say Programming Ape Say programming!