This is hacky and is not guaranteed to work in different implementations/versions of python.
The contents of the PriorityQueue
is kept in its queue
member, which is a plain list
. Therefor, you can test for item existence using in
. Since queues are typically used in a multi-threading/processing environment, you probably also want to lock (using its mutex
member):
def is_in_queue(x, q):
with q.mutex:
return x in q.queue
This is a linear lookup in a list, using the ==
operator on the items. __hash__
is not used.