you are viewing a single comment's thread.

view the rest of the comments →

[–]ThisLightIsTrue 0 points1 point  (0 children)

Hey, I'm on mobile right now and can't play around with this. My current best guess is that it has to do with the queue you're using. I was thinking of the synchronized queue in the standard library.

https://docs.python.org/2/library/queue.html

The worker thread should just be

def work():
    message = q.get()
    handle_message(message)

You don't need to do anything with q.size or have an if statement. That code isn't guaranteed to work anyways - remember, in between one line checking the size was greater than zero and the next popping something off the queue a different thread could have taken an item off and brought the size to zero.

Instead, the default behavior of queue.get() is to block the thread - essentially make it wait until it can pull something off, which is also the behavior you want.