清除队列中的所有项目 [英] Clear all items from the queue

查看:46
本文介绍了清除队列中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除队列.例如我在队列中有数据,但由于某种原因我不需要现有数据,只想清除队列.

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 way? Will this work:

oldQueue = Queue.Queue()

推荐答案

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

编辑为清晰和简洁起见,我省略了线程安全问题,但@Dan D 说得很对,以下更好.

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()

这篇关于清除队列中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆