Home  >  Article  >  Backend Development  >  Detailed introduction to python3 Queue (one-way queue)

Detailed introduction to python3 Queue (one-way queue)

高洛峰
高洛峰Original
2017-03-23 14:38:332368browse

Create queue


import queue
q = queue.Queue()

empty (if the queue is empty, return True)


##

import queue
q = queue.Queue()print(q.empty())#输出:True
full (if If the queue is full, return True)


import queue
q = queue.Queue(1) #指定队列大小q.put('a')print(q.full())#输出:True
put (put an element into the queue) get (remove an element from the queue) first-in-first-out principle


import queue
q = queue.Queue()
q.put('a')
q.put('b')print(q.get())#输出:a
get_nowait (remove an element immediately, without waiting)


#占位
put_nowait (put an element immediately, without waiting)


#占位
join(block the calling thread until all tasks in the queue are processed)


#占位
qsize(return to the queue Number of elements)


import queue
q = queue.Queue()
q.put('a')
q.put('b')print(q.qsize())#输出:2
task_done (After completing a task, send a signal to the queue where the task has been completed)


#占位

The above is the detailed content of Detailed introduction to python3 Queue (one-way queue). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn