# coding:utf-8
from multiprocessing import Queue
q = Queue(3) # 创建一个队列对象,队列长度为3
q.put(1)
q.put(2)
# q.put(3)
# q.put(4) # 当队列已满,继续放值,,会阻塞程序
try:
q.put_nowait(4)
except:
print("队列已经满了.")
print(q.get())
print(q.get())
print(q.get())
# print(q.get()) # 当队列空了,继续取值,也会阻塞程序
try:
q.get_nowait()
except:
print("队列已经空了.")
# 1
# 2
# 4
# 队列已经空了.
原文:https://www.cnblogs.com/lilyxiaoyy/p/10970863.html