python queue Queue

Queue

#1 surroundings##

Python3.7.3

#2 Start##

from queue import Queue,LifoQueue,PriorityQueue

#2.1 Queue type###

q =Queue(maxsize=0)
q =LifoQueue(maxsize=0)
q =PriorityQueue(maxsize=0)

# More details later

maxsize: maxsize is an integer that specifies the upper limit of the number of data that can be stored in the queue. Once the upper limit is reached, insertion will cause blocking until the data in the queue is consumed. If maxsize is less than or equal to 0, there is no limit on the queue size.


#2.2 operating###

put(item, block=True, timeout=None)

# item:Enrolled data(Any data type is fine)
# block:bool type,Default True
# timeout:overtime time,Default None
# 1. When block is the default value,If the queue is already in"Full team"status,Also continue to insert data into the queue,At this time, the value of timeout is the time when the program throws an exception(timeout=When None,The program is always in"Blockage"status,Unless there is data"Leave the team")
# 2. When block=When False,No matter what the timeout is,Just queue"Blockage"Throw an exception immediately
get(block=True, timeout=None)

# block:bool type,Default True
# timeout:overtime time,Default None
# 1. When block is the default value(True),If the queue is already in"air"status,Have to continue"Leave the team",At this time, the value of timeout is the time when the program throws an exception(timeout=When None,The program is always in"air转"status(Infinite loop),Unless there is data"Join the team")
# 2. When block=When False,No matter what the timeout is,Just queue"Idling"Throw an exception immediately
q.qsize()
# If the queue is empty, return True,Otherwise False
q.empty()
# If the queue is full, return True,Otherwise False
q.full()
q.queue.clear()

#2.3 PriorityQueue (PriorityQueue)

from queue import PriorityQueue
q =PriorityQueue()classJob(object):
 def __init__(self, priority, description):
  self.priority = priority
  self.description = description
  print('Join the team:', description)return

 def __lt__(self, other):return self.priority < other.priority
        
# The lower the number, the higher the priority
q.put(Job(1,"aaa"))
q.put(Job(2,"bbb"))
q.put(Job(8,"ccc"))
q.put(Job(3,"ddd"))print(q.get().description)print(q.get().description)print(q.get().description)print(q.get().description)


Recommended Posts

python queue Queue
Python Lesson 32-Queue
Python multithreading
Python CookBook
Python FAQ
Python3 dictionary
Python3 module
python (you-get)
Python string
Python descriptor
Python basics 2
Python notes
Python3 tuple
CentOS + Python3.6+
Python advanced (1)
Python decorator
Python IO
Python multithreading
Python toolchain
Python3 list
Python multitasking-coroutine
Python overview
python introduction
Python analytic
Python basics
07. Python3 functions
Python basics 3
Python multitasking-threads
Python functions
python sys.stdout
python operator
Python entry-3
Centos 7.5 python3.6
Python string
Python basics 4
Python basics 5
Centos6 install Python2.7.13
Python answers questions
Python basic syntax (1)
Python exit loop
Ubuntu16 upgrade Python3
Centos7 install Python 3.6.
ubuntu18.04 install python2
Python classic algorithm
Relearn ubuntu --python3
Python2.7 [Installation Tutorial]
Python string manipulation
Python 3.9 is here!
Python study notes (1)
python learning route
CentOS7 upgrade python3
Python review one
linux+ubuntu solve python
Functions in python
Python learning-variable types
CentOS install Python 3.6
7 features of Python3.9
ubuntu12.04 install python3
Python - centos6 installation
Centos7 install Python2.7
01. Introduction to Python