prefactor_core.queue.memory module
prefactor_core.queue.memory module
Section titled “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.
Example
Section titled “Example”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().
property closed : bool
Section titled “property closed : bool”Check if the queue has been closed.
- Returns: True if the queue is closed.
async get() → T
Section titled “async get() → T”Remove and return an item from the queue.
- Returns: The next item from the queue.
- Raises: QueueClosedError – If the queue is closed and empty.
async put(item: T) → None
Section titled “async put(item: T) → None”Add an item to the queue.
- Parameters: item – The item to add.
- Raises: QueueClosedError – If the queue has been closed.
size() → int
Section titled “size() → int”Return the current number of items in the queue.
- Returns: The queue size.