Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deepcopy a queue in python

Tags:

python

copy

queue

Hi How to deepcopy a Queue in python? Thanks

like image 929
Mike Avatar asked Dec 29 '22 09:12

Mike


1 Answers

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.

like image 105
kennytm Avatar answered Jan 13 '23 15:01

kennytm