如何深度复制python中的队列 [英] how to deepcopy a queue in python
问题描述
Hi如何深入复制python中的队列?
感谢
Hi How to deepcopy a Queue in python? Thanks
推荐答案
queue
模块用于同步线程之间的共享数据。 不是打算作为数据结构,它不支持复制(甚至不支持浅拷贝)。
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
创建一个队列的许多深层副本,但原始队列将被销毁。)
(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中的队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!