Get all items from thread Queue

后端 未结 6 1656
别那么骄傲
别那么骄傲 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

    I see you are using get_nowait() which according to the documentation, "return[s] an item if one is immediately available, else raise the Empty exception"

    Now, you happen to break out of the loop when an Empty exception is thrown. Thus, if there is no result immediately available in the queue, your function returns an empty items list.

    Is there a reason why you are not using the get() method instead? It may be the case that the get_nowait() fails because the queue is servicing a put() request at that same moment.

提交回复
热议问题