-
队列基本操作
-
多线程队列
============================================================================
from queue import Queue
q = Queue(5) # 创建一个容量为5的队列。如果给一个小于0的数,则队列为无限大小。(这是官方的解释,实际不是无限大小,而是跟内存有关)
存储数据
q.put(123) # 数值
q.put(‘hello world!’) # 字符串
q.put([‘hello’, ‘world’]) # 列表
q.put((‘hello’, ‘world’)) # 元组
q.put({‘hello’: ‘world’}) # 字典
如果再试图存储第六个,则会发生阻塞,因为容量已设定为5
q.put({‘hello’: ‘python’})
取出队列中的