I am wondering when a blocking get with no timeout on a python3 queue can return None.
The python3 queue documentation states:
Queue.get(block=True, timeout=None)
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).
For me this means that a get() with no arguments will wait on an element being in the queue and return only then, therefore always will return a value that is not None. Still in the example at the bottom of the queue documentation the following code is given:
while True:
item = q.get()
if item is None:
break
...
The explicit checking against the item being None implies that None can be returned. In which situations can this happen?
put()aNoneinto the queue explicitly as an end marker (which, by the way, is a good technique to signal to the partner thread that no more communication will happen on the queue). - blubberdiblub