Home > Net >  Python: will a thread ever unblock while hanging on a `Queue.get(block=True)` call if the queue is s
Python: will a thread ever unblock while hanging on a `Queue.get(block=True)` call if the queue is s

Time:06-28

TLDR: Would a blocking get be unblocked by a queue that would be terminated in some way?


Long question:

Okay, so I know that the thread will hang if the queue (multiprocessing.Queue) remains empty forever while trying to fetch something from it with a blocking get.

But suppose now that in another thread or process, I close the queue with queue.close(), call queue.cancel_join_thread(), and then also queue.join_thread().

With the blocking "get" raise an exception or something upon trying to kill the queue like that?

Thanks!

CodePudding user response:

Yes, an exception is raised if the queue is closed.

From the latest documentation:

Under Queue.get() the following statement occurs:

"Changed in version 3.8: If the queue is closed, ValueError is raised instead of OSError."

  • Related