Skip to content

prefactor_core.queue.memory module

In-memory queue implementation.

Provides a simple, unbounded in-memory queue suitable for most use cases. Data is lost on process termination - use a persistent queue implementation for durability requirements.

class prefactor_core.queue.memory.InMemoryQueue

Section titled “class prefactor_core.queue.memory.InMemoryQueue”

Bases: Queue[T]

Unbounded in-memory queue implementation.

This is the default queue implementation. It’s simple, fast, and suitable for most use cases. All data is stored in memory and will be lost if the process terminates before processing completes.

The queue uses asyncio.Queue internally for thread-safe operations.

queue = InMemoryQueue() await queue.put(“operation”) item = await queue.get() await queue.close()

async close(num_waiters: int = 1) → None

Section titled “async close(num_waiters: int = 1) → None”

Close the queue.

After closing, no new items can be added. Workers will continue to process existing items until the queue is empty, then exit.

  • Parameters: num_waiters – Number of sentinel values to enqueue to wake up that many workers currently blocked in get().

Check if the queue has been closed.

  • Returns: True if the queue is closed.

Remove and return an item from the queue.

  • Returns: The next item from the queue.
  • Raises: QueueClosedError – If the queue is closed and empty.

Add an item to the queue.

  • Parameters: item – The item to add.
  • Raises: QueueClosedError – If the queue has been closed.

Return the current number of items in the queue.

  • Returns: The queue size.