from queue import Queue
# q = Queue(3) # 设置队列最大的长度
# q.empty() # 判断队列是否为空 True False
# q.qsize() # 判断队列的大小
# q.full() # 判断队列是都满了 True False
# q.put(1) q.put(block=True) # 加入一个队列元素 block默认是阻塞式
# q.get() q.get(block=True) # 取出队列某个元素 默认是第一个元素 block默认是阻塞式
# for i in range(3):
# q.put(i)
#
# for i in range(3):
# print(q.get())
import time
import threading
def set_value(q):
index = 0
while True:
q.put(index)
index += 1
time.sleep(2)
def get_value(q):
while True:
print(q.get())
def main():
q = Queue(4)
t1 = threading.Thread(target=set_value, args=[q])
t2 = threading.Thread(target=get_value, args=[q])
t1.start()
t2.start()
if __name__ == '__main__':
main()