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).
(It is possible to construct many deepcopy's of a Queue by .get
and .put
, but the original Queue will be destroyed.)
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…