python - Queue队列
2023-09-27 14:29:10 时间
# coding=utf-8
from Queue import Queue
from threading import Thread, Lock
# 创建一个实例
queue = Queue()
# 遍历列表入队列
for i in range(10):
queue.put(i) # 入队列
print 'size is :', queue.qsize() # 打印队列的长度
print 'qsize = ', queue.qsize() # 打印对列的长度
# 从队列中取出值,直到队列为空
while not queue.empty():
print queue.get() # 出队列,并打印
输出如下:
size is : 1
size is : 2
size is : 3
size is : 4
size is : 5
size is : 6
size is : 7
size is : 8
size is : 9
size is : 10
qsize = 10
0
1
2
3
4
5
6
7
8
9
Process finished with exit code 0
相关文章
- 数据结构Python版(四)——队列
- 打基础丨Python图像处理入门知识详解
- Python迭代和迭代器详解
- 【Python】Padas DataFrame和列表List相互转换
- Python 源码分析:queue 队列模块
- 第28天:Python 标准库之 sys 模块详解
- Python 字典(Dictionary) get()方法
- python 3计算KL散度(KL Divergence)
- python基础笔记
- python 操作消息队列
- 15.Python Package目录及打包并发布到PyPI
- 成功解决:Can‘t find Python executable “python“, you can set the PYTHON env variable.
- python使用ssdb的队列,用于替换canal+rabbitmq
- python-栈和队列
- python 爬虫程序异常处理模块 - retrying
- python学习之数据结构(四):数据结构与算法:栈、队列