python3 线程队列queue

# -*- coding: utf-8 -*-
import queue


if __name__ == '__main__':
    '''先进先出'''
    que = queue.Queue(3)
    que.put("first")
    que.put("second")
    que.put(["a", "b", "c"])

    print(que.get())
    print(que.get())
    print(que.get())

# first
# second
# ['a', 'b', 'c']

    '''后进先出'''
    lifo_que = queue.LifoQueue(3)
    lifo_que.put("first")
    lifo_que.put("second")
    lifo_que.put(["a", "b", "c"])

    print(lifo_que.get())
    print(lifo_que.get())
    print(lifo_que.get())

# ['a', 'b', 'c']
# second
# first


    '''优先级队列,数字越小优先级越高,越先取出来'''
    priority_que = queue.PriorityQueue(3)
    priority_que.put((3, "first"))
    priority_que.put((8, "second"))
    priority_que.put((2, ["a", "b", "c"]))

    print(priority_que.get())
    print(priority_que.get())
    print(priority_que.get())

# (2, ['a', 'b', 'c'])
# (3, 'first')
# (8, 'second')

 

posted on 2019-06-16 19:59  lilyxiaoyy  阅读(1127)  评论(0编辑  收藏  举报

返回
顶部