Question:
This is Python 3.10. I use aPriorityQueue
as a way to track Actors’ turn order in my game. It’s just a simple roguelike. I don’t use the synchronization features of the PriorityQueue
. My code:TypeError: cannot pickle '_thread.lock' object
. From what I understand PriorityQueue is not pickle-able. I’ve read here that Queue.Queue
has a pickle-able alternative of collections.deque
if the synchronization stuff is not necessary. Is there such an alternative to PriorityQueue
, or is there a way to pickle it anyway? Other than implementing my own simplified version of PriorityQueue
?Answer:
As you don’t need the synchronisation features of PriorityQueue, just use the light-weightheapq
module. It provides functions (not methods) to work on a plain list:If you have better answer, please add a comment about this, thank you!