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:
def queue_get_all(q): items = [] while 1: try: items.append(q.get_nowait()) except Empty, e: break return items
Is this a good way to do it ?
Edit:
I’m asking because sometimes the waiting thread gets stuck for a few seconds without taking out new results.
The ‘stuck’ problem turned out to be because I was doing the processing in the idle event handler, without making sure that such events are actually generated by calling wx.WakeUpIdle, as is recommended.
I’d be very surprised if the
get_nowait()call caused the pause by not returning if the list was empty.Could it be that you’re posting a large number of (maybe big?) items between checks which means the receiving thread has a large amount of data to pull out of the
Queue? You could try limiting the number you retrieve in one batch:This would limit the receiving thread to pulling up to 10 items at a time.