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
- 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 queue LifoQueue — LIFO
This article is published by the blog – Ape Say Programming Ape Say programming!