线程queue

 线程queue

queue的三种用法:
先进先出->队列

import queue

q=queue.Queue(3)
q.put('first')
q.put('second')
q.put('third')

print(q.get())
print(q.get())
print(q.get())

'''
结果(先进先出):
first
second
third
'''

后进先出->堆栈

q = queue.LifoQueue(3) #后进先出->堆栈
q.put('1')
q.put('2')
q.put('3')

print(q.get())
print(q.get())
print(q.get_nowait())
'''
3
2
1
'''

优先级队列

q = queue.PriorityQueue(3)#优先级队列
# 数字越小优先级越高
q.put((10,'1'))
q.put((50,'2'))
q.put((30,'3'))

print(q.get())
print(q.get())
print(q.get())

'''
(10, '1')
(30, '3')
(50, '2')
'''
posted @ 2018-07-04 14:56  游走在边缘的人  阅读(90)  评论(0编辑  收藏  举报