I have a Python queue in which I add items in a thread like so
import queue
import threading
_myQueue = queue.Queue()
threading.Thread(target=worker, daemon=True).start()
def worker():
while True:
item = _myQueue.get()
# Do something with this item
_myQueue.task_done()
def add_item(item):
_myQueue.put(item)
My question is am I able to edit or delete items from this queue while my worker thread is doing something between _myQueue.get() and _myQueue.task_done():
item = _myQueue.get()
# Do something with this item
_myQueue.task_done()
For example if an item is ‘cancelled’ and no longer needs processed.