morpheus.utils.producer_consumer_queue.ProducerConsumerQueue

(Latest Version)
class ProducerConsumerQueue(maxsize=0)[source]

Bases: queue.Queue, Generic[morpheus.utils.producer_consumer_queue._T]

Custom queue.Queue implementation which supports closing and uses recursive locks

Parameters
maxsizeint

Maximum size of queue. If maxsize is <= 0, the queue size is infinite.

Methods

close()

Close the queue.

empty()

Return True if the queue is empty, False otherwise (not reliable!).

full()

Return True if the queue is full, False otherwise (not reliable!).

get([block, timeout])

Remove and return an item from the front of the queue.

get_nowait()

Remove and return an item from the queue without blocking.

is_closed()

Check if the queue is closed.

join()

Blocks until the queue has been closed and all tasks are completed

put(item[, block, timeout])

Put an item into the back of the queue.

put_nowait(item)

Put an item into the queue without blocking.

qsize()

Return the approximate size of the queue (not reliable!).

task_done()

Indicate that a formerly enqueued task is complete.

close()[source]

Close the queue.

empty()[source]

Return True if the queue is empty, False otherwise (not reliable!).

This method is likely to be removed at some point. Use qsize() == 0 as a direct substitute, but be aware that either approach risks a race condition where a queue can grow before the result of empty() or qsize() can be used.

To create code that needs to wait for all queued tasks to be completed, the preferred technique is to use the join() method.

full()[source]

Return True if the queue is full, False otherwise (not reliable!).

This method is likely to be removed at some point. Use qsize() >= n as a direct substitute, but be aware that either approach risks a race condition where a queue can shrink before the result of full() or qsize() can be used.

get(block=True, timeout=None)[source]

Remove and return an item from the front of the queue. When block is True and the queue is empty it will block up to timeout seconts, raising a queue.Empty when either block is False or the timeout has exceeded. A Closed exception is raised if the queue is closed.

get_nowait()[source]

Remove and return an item from the queue without blocking.

Only get an item if one is immediately available. Otherwise raise the Empty exception.

is_closed()[source]

Check if the queue is closed.

join()[source]

Blocks until the queue has been closed and all tasks are completed

put(item, block=True, timeout=None)[source]

Put an item into the back of the queue. When block is True and the queue is full it will block up to timeout seconds, raising a queue.Full when either block is False or the timeout has exceeded. A Closed exception is raised if the queue is closed.

put_nowait(item)[source]

Put an item into the queue without blocking.

Only enqueue the item if a free slot is immediately available. Otherwise raise the Full exception.

qsize()[source]

Return the approximate size of the queue (not reliable!).

task_done()[source]

Indicate that a formerly enqueued task is complete.

Used by Queue consumer threads. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.

If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).

Raises a ValueError if called more times than there were items placed in the queue.

© Copyright 2023, NVIDIA. Last updated on Apr 11, 2023.