Clear all items from the queue

前端 未结 3 1955
无人及你
无人及你 2020-12-13 03:48

How can I clear a queue. For example I have datas in a queue, but for some reason I don\'t need the existing data, and just want to clear the queue.

Is there any wa

3条回答
  •  天命终不由人
    2020-12-13 04:17

    q = Queue.Queue()
    q.queue.clear()
    

    EDIT I omitted the issue of thread safety for clarity and brevity, but @Dan D is quite correct, the following is better.

    q = Queue.Queue()
    with q.mutex:
        q.queue.clear()
    

提交回复
热议问题