Hi How to deepcopy a Queue in python? Thanks
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With