How can I remove an arbitrary item from a priority queue. Suppose I have a PriorityQueue for jobs. I have a job I want to “cancel” so I need to remove it from the queue, how can I do that?
UPDATE
To add to the answer, a related question: https://stackoverflow.com/a/9288081/292291
I’m assuming you’re using
heapq. The documentation has this to say about this problem, which seems quite reasonable:The documentation provides some basic example code to show how this can be done, which I reproduce here verbatim: