API Reference¶
Shared Circular Buffer¶
-
class
shared_cbuff.buffer.SharedCircularBuffer(name: str, *, create: bool = False, item_size: int = 1, length: int = 2)¶ An implementation of a circular buffer built on top of
multiprocessing.shared_memory.SharedMemoryto allow a fast method to send and receive data between multiple python instances.- Parameters
name (
str) – The name of the memory block, used when linkingSharedCircularBufferinstances together.- Keyword Arguments
create (
bool) – Whether the class should create a newSharedMemoryinstance or link itself to one that already exists. Defaults toFalseitem_size (
int) – The number of bytes each item in the buffer should take up. Defaults to1.length (
int) – The length of the buffer. Defaults to2.
Warning
All instances that connect to the same shared memory must have the
name,item_sizeandlengthparameters passed in if they differ from default otherwise reading from the shared memory will not work correctly.-
cleanup() → None¶ Closes the connection to the
SharedMemoryblock and unlinks it if this class was the writer to the buffer.This method is automatically called before the program exits.
- Returns
None
-
item_size¶ The maximum size of each item stored in bytes.
-
length¶ The length of the buffer.
-
name¶ The name of the shared memory block this instance is attached to.
-
popitem() → Optional[int]¶ Pops an item from the buffer.
- Returns
Item removed from the buffer, or
Noneif there is nothing to read.- Return type
Optional[
int]- Raises
ReadOperationsForbidden – The buffer cannot be read from by this instance.
-
popmany(n: int) → Sequence[int]¶ Pops up to a maximum of
nitems from the buffer.- Returns
Items removed from the buffer.
- Return type
Sequence[
int]- Raises
ReadOperationsForbidden – The buffer cannot be read from by this instance.
Errors¶
-
exception
shared_cbuff.errors.CBuffException¶ Bases:
ExceptionBase exception for all exceptions raised by the library.
-
exception
shared_cbuff.errors.WriteOperationsForbidden¶ Bases:
shared_cbuff.errors.CBuffExceptionException raised when a write operation is attempted but is not permitted.
-
exception
shared_cbuff.errors.ReadOperationsForbidden¶ Bases:
shared_cbuff.errors.CBuffExceptionException raised when a read operation is attempted but is not permitted.
-
exception
shared_cbuff.errors.BufferAlreadyCreated¶ Bases:
shared_cbuff.errors.CBuffExceptionException raised when attempting to create multiple buffers with the same name.