queue — A synchronized queue class
https://docs.python.org/3.6/library/queue.html
https://github.com/python/cpython/blob/3.6/Lib/queue.py
The queue
module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue
class in this module implements all the required locking semantics. It depends on the availability of thread support in Python; see the threading
module.
The module implements three types of queue, which differ only in the order in which the entries are retrieved. In a FIFO queue, the first tasks added are the first retrieved. In a LIFO queue, the most recently added entry is the first retrieved (operating like a stack). With a priority queue, the entries are kept sorted (using the heapq
module) and the lowest valued entry is retrieved first.
Internally, the module uses locks to temporarily block competing threads; however, it is not designed to handle reentrancy within a thread.
The queue
module defines the following classes and exceptions:
- class
queue.
Queue
(maxsize=0) -
Constructor for a FIFO queue. maxsize is an integer that sets the upperbound limit on the number of items that can be placed in the queue. Insertion will block once this size has been reached, until queue items are consumed. If maxsize is less than or equal to zero, the queue size is infinite.
- class
queue.
LifoQueue
(maxsize=0) -
Constructor for a LIFO queue. maxsize is an integer that sets the upperbound limit on the number of items that can be placed in the queue. Insertion will block once this size has been reached, until queue items are consumed. If maxsize is less than or equal to zero, the queue size is infinite.
- class
queue.
PriorityQueue
(maxsize=0) -
Constructor for a priority queue. maxsize is an integer that sets the upperbound limit on the number of items that can be placed in the queue. Insertion will block once this size has been reached, until queue items are consumed. If maxsize is less than or equal to zero, the queue size is infinite.
The lowest valued entries are retrieved first (the lowest valued entry is the one returned by
sorted(list(entries))[0]
). A typical pattern for entries is a tuple in the form:(priority_number, data)
.
- exception
queue.
Empty
-
Exception raised when non-blocking
get()
(orget_nowait()
) is called on aQueue
object which is empty.
- exception
queue.
Full
-
Exception raised when non-blocking
put()
(orput_nowait()
) is called on aQueue
object which is full.
queue — A synchronized queue class的更多相关文章
- 多进程(了解):守护进程,互斥锁,信号量,进程Queue与线程queue(生产者与消费者模型)
一.守护进程 主进程创建守护进程,守护进程的主要的特征为:①守护进程会在主进程代码执行结束时立即终止:②守护进程内无法继续再开子进程,否则会抛出异常. 实例: from multiprocessing ...
- C++ 如何用百行代码实现线程安全的并发队列 | concurrent queue or blocking queue implemented in cpp
本文首发于个人博客https://kezunlin.me/post/cabccf5c/,欢迎阅读最新内容! concurrent queue or blocking queue implemented ...
- Windows Azure Service Bus (4) Service Bus Queue和Storage Queue的区别
<Windows Azure Platform 系列文章目录> 熟悉笔者文章的读者都了解,Azure提供两种不同方式的Queue消息队列: 1.Azure Storage Queue 具体 ...
- Laravel Scout 开启队列, 自定义queue name和queue connection
scout.php的默认配置: 'queue' => env('SCOUT_QUEUE', false), 修改为: 'queue' => [ 'queue' => env('SCO ...
- 线程queue与进程queue
进程queue: from multiprocessing import Queue,Process def func(qq): qq.put('function:我要放数据,给你来取...') if ...
- 进程Queue、线程Queue、堆栈、生产者消费者模型
没学队列之前,可以用文件实现进程之间通信 但是有2个问题: 1. 速度慢:文件是保存在硬盘空间 2. 为了数据安全要加锁(处理锁是一件很麻烦的事,容易死锁,建议自己轻易不要处理锁) 队列:队列是基于管 ...
- UVa540 Team Queue(队列queue)
队列 STL队列定义在头文件<queue>中, 用“ queue<int>s ” 方式定义, 用push()和pop()进行元素的入队和出队操作, front()取队首元素(但 ...
- 进程Queue和线程Queue区别
进程Queue from multiprocessing import Queue q=Queue() 线程Queue import queue q=queue.Queue()
- Python教程大纲
缘起:最近想在部门推Python语言,写这个blog主要就是个教程大纲,之前先列出一些资源:Python历史:http://www.docin.com/p-53019548.html ...
随机推荐
- POJ 2643 Election
Election Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3558 Accepted: 1692 Descript ...
- Android单个按钮自定义Dialog
代码改变世界 Android单个按钮自定义Dialog dialog_layout.xml <?xml version="1.0" encoding="utf-8& ...
- BZOJ 1072 [SCOI2007]排列perm ——状压DP
[题目分析] 没什么好说的,水题. 代码比较丑,结果需要开long long 时间爆炸 [代码] #include <cstdio> #include <cstring> #i ...
- BZOJ 2190仪仗队【欧拉函数】
问题的唯一难点就是如何表示队长能看到的人数?如果建系,队长所在的点为(0,0)分析几组数据就一目了然了,如果队长能看到的点为(m,n),那么gcd(m,n)=1即m n 互质或者是(0,1),(1,0 ...
- 雅礼培训4.3 Problem A 【点分治】
题目简述 一个\(N\)个节点的树,有\(M\)个炸弹分布在一些节点上,有各自的威力,随着其他点距离增大对其他点的伤害呈等差减小,直至为0 问每个点受到的伤害 题解 QAQ考场代码没处理好有些炸弹威力 ...
- PC端有什么好用的倍速播放的软件?
倍速播放的目的是让自己可以以更快的速度去看视频, 加快获取信息的效率 potplay吧,和KMP是一个作者.加速播放快捷键是c,减速时x,z恢复正常.下载官网 Global Potplayer
- P1582 倒水 (二进制)
题目描述 一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水.接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子.每次他选择两个当前含水量相同的瓶子,把一个瓶子的水全部倒 ...
- jvm gc回收机制
jdk8取消永久代,增加metaspace元空间.使用本地内存,不使用堆内存. jstat -gcutil jstat -gccause pid 1 每格1毫秒输出结果jstat -gccause p ...
- PXC小结
PXC使用到的端口号 3306 数据库对外服务的端口号(视具体情况而定) 4444 请求SST SST: 指数据一个镜象传输 xtrabackup , rsync ,mysqldump 4567 : ...
- python 之文件操作
一.文件基本操作 1.文件的打开 打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作 文件句柄 = open('文件路径', '模式') 2. ...