1

In the python documentation, it says

exception Queue.Empty
Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty.

So I wonder whether the following coding will ever raise the Queue.Empty exception because the way it use 'get' method seems non-blocking.

Here is the code.

try:
    request = self._requests_queue.get(True, self._poll_timeout)
except Queue.Empty:
    continue

1 Answer 1

2

The documentation says everything you need to know to answer the question (emphasis mine):

Queue.get([block[, timeout]])

Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time. Otherwise (block is false), return an item if one is immediately available, else raise the Empty exception (timeout is ignored in that case).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.