directory

  • Python thread Queue classification
  • LifoQueue is a Python thread queue
  • The LifoQueue function is introduced in Python
  • LifoQueue is used by Python threads
  • Five. Guess you like it

Recommended path for learning Python: Python Learning Directory >> Python Basics

In Python thread FIFO Queue Queue – article has introduced the FIFO Queue Queue, and today is the second to introduce: thread Queue LifoQueue – LIFO, data after the advanced type, what is the difference between the two?

Python thread Queue classification

  • 1. Thread Queue – FIFO(first-in, first-out Queue)****, namely which data is stored first, which data is taken first when fetching data, 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, when the data is taken first, the same as the pistol magazine in life, the last bullet into the first shot;
  • 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;

Only the second thread Queue(LIFO) will be covered today, and the last will be covered in more detail in the next article!

LifoQueue is a Python thread queue

As mentioned above, in contrast to the Queue in the previous article, the data stored last is retrieved first, and the data stored first is retrieved last, as shown in the figure below:

If FIFO is to eat what pull what, then LIFO is to eat what vomit what, eat after vomit, eat after vomit ~ ~ is really heavy taste!

The LifoQueue function is introduced in Python

The Python thread Queue — FIFO is covered in detail. Both belong to queues and have the same function!

LifoQueue is used by Python threads

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python thread advance after queue lifoqueue. py @time :2021/05/05 07:37 @motto: A thousand miles without a step, a river without a small stream, the wonderful life of the program needs to be accumulated with perseverance! Import queue import threading import time q= queue.lifoqueue (5) Q =queue.LifoQueue() def put(): for I in range(10): Q.print () print('ok') def get(): for I in range(10): Value = q.g et () print (" data removed from the queue "% d % value) q.t ask_done () t1 = threading. Thread (target = put, args = ()) t1. The start () Threading.thread (target=get,args=()) t2.start() 1 0 is placed into the queue data is placed into the data to the queue is placed into 2 to 3 is placed into the queue data to the queue data is placed into 4 to 5 is placed into the queue queue data in the data is placed into 6 to 7 is placed into the queue data to the queue data in 8 is placed into the data to the queue 9 is placed into the data to the queue and removed from the queue Data 8 Fetch data from the queue 7 Fetch data from the queue 6 Fetch data from the queue 5 Fetch data from the queue 4 Fetch data from the queue 3 Fetch data from the queue 2 Fetch data from the queue 1 Fetch data from the queue 0 Fetch data from the queue OK ""Copy the code

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 queue LifoQueue — LIFO

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