Get all items from thread Queue

后端 未结 6 1653
别那么骄傲
别那么骄傲 2021-02-13 05:14

I have one thread that writes results into a Queue.

In another thread (GUI), I periodically (in the IDLE event) check if there are results in the queue, like this:

6条回答
  •  攒了一身酷
    2021-02-13 05:42

    The simplest method is using a list comprehension:

    items = [q.get() for _ in range(q.qsize())]
    

    Use of the range function is generally frowned upon, but I haven't found a simpler method yet.

提交回复
热议问题