Python并发编程-队列

队列

  • IPC = Inter-Process Communication
  • 队列 先进先出
  • 队列的几种方法

    put()

    full()

    get()

    empty()

    get-nowait()

from multiprocessing import Queue
q = Queue(5) #队列的大小为5
q.put(1)
q.put(2)
q.put(3)
q.put(4)
q.put(5) #放入属性
print(q.full()) #查看队列是否满
print(q.get()) #q.get取走队列里的数据
print(q.get())
print(q.get())
print(q.empty())#查看队列是否为空
print(q.get()) #如果值为空则队列阻塞
while True:
    try:
        q.get_nowait() #get的时候如果没有值则不等待,不阻塞
    except:
        print('队列已空')
        time.sleep(1)
原文地址:https://www.cnblogs.com/konglinqingfeng/p/9693625.html