radloggerpy.datastructures.device_data_buffer module
- class radloggerpy.datastructures.device_data_buffer.DeviceDataBuffer(condition: Condition)[source]
Bases:
object
Native list protected by locks for devices as data buffer
Read and Write lock are used in reverse because CPython GIL allows multiple threads to add elements concurrently without the List entering an invalid state. When all elements are fetched and cleared the write lock is used because it has preference over the readers.
All readings in the data buffer must be of type RadiationReading as enforced while calling add_elements.
Adding readings will acquire and notify on the condition as this will wake up the DeviceManager.
- add_readings(readings: List[RadiationReading])[source]
Add the readings to the buffer
Add all the readings to the buffer and remove any elements not of type :py:class: ‘~.RadiationReading’.
- Parameters:
readings (List of :py:class: '~.RadiationReading' instances) – The readings to be added to the data buffer
- Returns:
True if the elements were successfully added False otherwise
- fetch_clear_readings() List[RadiationReading] [source]
Retrieve all the readings from the buffer and clear the buffer
Gets an exclusive write lock to create a reference to current data and subsequently clears the internal buffer. Afterwards it returns the previous internal readings. If getting the exclusive write lock failed it will return None instead.
- Returns:
All the buffered readings available or None if the lock fails
- Return type:
List of :py:class: ‘~.RadiationReading’ instances | None