Is it possible to remove an item and have the queue for multithreading reorder itself in Python?
I have users queued up in a Queue, but when it's time to process the user and if the user disconnects, that will raise an issue.
Is there a way to do this?
Thanks
Queue
objects do not provide random access. However, you can achieve the same goal by retaining references to the objects in the queue somewhere else and marking them stale. When the object is read from the queue, the consumer can check to see if the object is stale, and if it is, throw it away and read again.
You may also find value in the PriorityQueue
class, where you put (priority, message)
instead of just message
onto the queue, and the data with the lowest priority
value is always the next one read from the queue. This by itself won't solve your issue, but it may give you a way to prioritize the oldest request or something like that.
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