how to deepcopy a queue in python(如何在python中深度复制队列)
问题描述
如何在 python 中深度复制队列?谢谢
Hi How to deepcopy a Queue in python? Thanks
推荐答案
queue<Python 中的/code> 模块 用于同步线程之间的共享数据.它不是打算用作数据结构,并且不支持复制(甚至不支持浅复制).
The queue module in Python is used for synchronizing shared data between threads. It is not intended as a data structure and it doesn't support copying (not even shallow copy).
(.get和.put可以对一个Queue进行多次deepcopy,但是原来的Queue会被销毁.)
(It is possible to construct many deepcopy's of a Queue by .get and .put, but the original Queue will be destroyed.)
如果您想将队列(或堆栈)作为数据结构,使用 collections.deque.如果您想要优先级队列,请使用 heapq 模块.deque 支持 deepcopy.heapq 由列表支持,因此也支持 deepcopy.
If you want to have a queue (or stack) as a data structure, use a collections.deque. If you want a priority queue, use the heapq module. The deque supports deepcopy. heapq is backed by a list, so deepcopy is also supported.
这篇关于如何在python中深度复制队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在python中深度复制队列
基础教程推荐
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
