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

Detailed introduction to python3 Queue (one-way queue)

高洛峰
Release: 2017-03-23 14:38:33
Original
2396 people have browsed it

Create queue


import queue
q = queue.Queue()
Copy after login

empty (if the queue is empty, return True)


##

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


import queue
q = queue.Queue(1) #指定队列大小q.put('a')print(q.full())#输出:True
Copy after login
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
Copy after login
get_nowait (remove an element immediately, without waiting)


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


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


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


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


#占位
Copy after login
Copy after login
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template