import Queue q = Queue.Queue(2) print q.empty() q.put('eeee') q.put('bb') print q.qsize() #返回值为2 q.get() #get一个,则Queue中会空出来一个位置 print q.qsize() #返回值为1
print q.queue #查看当前队列中的内容函数
q.queue.clear() #清空当前队列spa
import Queue q = Queue.Queue(2) print q.empty() for i in range(1,4): try: q.put_nowait(i) #使用put_nowait()将数据放入Queue,若是队列满则抛出Full error。若是直接使用q.put()则当Queue满时,会产生死锁。取数据则使用print q.get_nowait(),同put_nowait() except: print ‘q is full’ print q.qsize()
while not q.empty(): print q.get_nowait() #取值:先进先出
import Queue q = Queue.Queue(20) for i in range(1,8): try: q.put_nowait(i) except: print 'q is full' q.queue.reverse() #倒序取值:先进后出 while not q.empty(): print q.get_nowait()