use empty method
if queue1.empty():
pass
else:
# get items from the queue
Note: doc says "not reliable" (no kidding).
I suppose that's because it can return True (queue is empty) while a message is posted, so the operation is not as atomic as catching the exception. Well, followed by a get_nowait() call I suppose it doesn't matter unless some other thread can consume the queue as well, in which case a racing condition could occur and the queue could be empty when you try to read from it!
Python
docs.python.org › 3 › library › queue.html
queue — A synchronized queue class
February 23, 2026 - Constructor for an unbounded FIFO queue. Simple queues lack advanced functionality such as task tracking. Added in version 3.7. ... Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty.
Faucet
docs.faucet.nz › en › 1.6.15 › _modules › queue.html
queue — Python documentation
Only enqueue the item if a free slot is immediately available. Otherwise raise the Full exception. ''' return self.put(item, block=False) def get_nowait(self): '''Remove and return an item from the queue without blocking. Only get an item if one is immediately available.
GitHub
github.com › python › asyncio › issues › 265
Queue.get_nowait() and Queue.get() raise AssertionError when there are multiple tasks waiting for free slots. · Issue #265 · python/asyncio
September 23, 2015 - import asyncio queue = asyncio.Queue(2) async def putter(item): await queue.put(item) async def getter(): await asyncio.sleep(1) num = queue.qsize() try: for _ in range(num): item = queue.get_nowait() except AssertionError as e: print(e) asyncio.ensure_future(putter(0)) asyncio.ensure_future(putter(1)) asyncio.ensure_future(putter(2)) asyncio.ensure_future(putter(3)) asyncio.get_event_loop().run_until_complete(getter())
Author manipopopo
Readthedocs
eventlet.readthedocs.io › en › latest › modules › queue.html
queue – Queue class — Eventlet 0.40.0 documentation
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.
GitHub
github.com › python › cpython › blob › main › Lib › asyncio › queues.py
cpython/Lib/asyncio/queues.py at main · python/cpython
def get_nowait(self): """Remove and return an item from the queue. · Return an item if one is immediately available, else raise QueueEmpty. · Raises QueueShutDown if the queue has been shut down and is empty, or · ...
Author python
Python
docs.python.org › 3.5 › library › asyncio-queue.html
18.5.8. Queues — Python 3.5.10 documentation
December 18, 2020 - A subclass of Queue that retrieves most recently added entries first. ... Exception raised when the get_nowait() method is called on a Queue object which is empty.
Read the Docs
python.readthedocs.io › en › latest › library › queue.html
17.7. queue — A synchronized queue class
November 15, 2017 - Constructor for an unbounded FIFO queue. Simple queues lack advanced functionality such as task tracking. Added in version 3.7. ... Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty.
University of New Brunswick
cs.unb.ca › ~bremner › teaching › cs2613 › books › python3-doc › library › queue.html
queue — A synchronized queue class — Python 3.9.2 documentation
Constructor for an unbounded FIFO queue. Simple queues lack advanced functionality such as task tracking. New in version 3.7. ... Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty.
Medium
medium.com › @surve.aasim › process-synchronization-using-multiprocessing-queue-4a2702cc6f5e
Process Synchronization using multiprocessing.Queue | by Aasim | Medium
August 17, 2023 - Blocking Operations: When a process attempts to extract data from an empty queue using queue.get(), it remains blocked until data becomes available. Similarly, if a process endeavors to put data into a full queue using queue.put(), it remains blocked until space is available. Non-Blocking Operations: Non-blocking alternatives include queue.put_nowait() and queue.get_nowait().
Read the Docs
stackless.readthedocs.io › en › 2.7-slp › library › queue.html
8.10. Queue — A synchronized queue class — Stackless-Python 2.7.15 documentation
Queue.get_nowait()¶ · Equivalent to get(False). Two methods are offered to support tracking whether enqueued tasks have been fully processed by daemon consumer threads. Queue.task_done()¶ · Indicate that a formerly enqueued task is complete. Used by queue consumer threads.
GitHub
github.com › python › cpython › blob › main › Lib › queue.py
cpython/Lib/queue.py at main · python/cpython
item = self._get() self.not_full.notify() return item · · def put_nowait(self, item): '''Put an item into the queue without blocking. · Only enqueue the item if a free slot is immediately available.
Author python
Friendliness
friendliness.dev › 2019 › 06 › 18 › python-nowait
When to use concurrent.futures.wait versus Queue.get (blocking) in Python
June 18, 2019 - def _nowait(futures): """Separate finished and unfinished threads, much like :func:`concurrent.futures.wait`, but don't wait. """ done = [] not_done = [] for future in futures: if future.done(): done.append(future) else: not_done.append(future) return done, not_done · The final implementation blocks on getting the results from the queue.
Readthedocs
pydoc-zh.readthedocs.io › en › latest › library › queue.html
8.10. Queue — A synchronized queue class — Python 2.7.6 documentation
Queue.get_nowait()¶ · Equivalent to get(False). Two methods are offered to support tracking whether enqueued tasks have been fully processed by daemon consumer threads. Queue.task_done()¶ · Indicate that a formerly enqueued task is complete. Used by queue consumer threads.
Post.Byes
post.bytes.com › home › forum › topic › python
why the method get() of python Queue is hang on there? - Post.Byes
August 14, 2006 - Since queues are meant to communicate between threads - and also often to synchronize them -, the default behaviour for the get when the queue is empty is to wait for something to be put in it. If you want your second get to fail, use the get_nowait method. HTH -- python -c "print ''.join([chr(154 ...