zoukankan      html  css  js  c++  java
  • 队列queue

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    # @Time    : 2018/6/19 9:11
    # @File    : 线程queue.py


    import queue

    # q = queue.Queue(3)  # 先进先出- 队列
    #
    # q.put('first')
    # q.put(2)
    # q.put('third')
    # # q.put(4)
    # # 第四个放不进去是因为put有一个默认参数block=True阻塞,修改为False报错queue.full
    # # timeout=3 超过3秒也是报错
    #
    #
    # print(q.get())
    # print(q.get())
    # print(q.get())
    # # print(q.get(block=True, timeout=3))
    # # print(q.get(block=False, ))  # q.get_nowait()

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

    q = queue.PriorityQueue()  # 优先级队列,数字越小优先级越高
    q.put((10, 'one'))
    q.put((40, 'two'))
    q.put((30, 'three'))

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

    # 结果
    # (10, 'one')
    # (30, 'three')
    # (40, 'two')

  • 相关阅读:
    自己写的asp日历控件
    处处留心皆学问
    模块化闲谈
    原理……
    DIV和SPAN的区别
    javascript学习感触
    CSS 匹配顺序
    配置闲谈
    找到的一个读取shape数据的代码
    问题和收获
  • 原文地址:https://www.cnblogs.com/fmgao-technology/p/9197147.html
Copyright © 2011-2022 走看看