def test_atomic_value_try_update_fail(): raw_value = random.random() value = AtomicValue(raw_value) value.lock.acquire() assert not value.try_update(random.random()) value.lock.release() assert raw_value == value.get_value()
def test_atomic_value_try_update_succeed(): raw_value = random.random() value = AtomicValue(raw_value) value.lock.acquire() value.lock.release() assert value.try_update(random.random()) assert raw_value != value.get_value()
def digest_next_sensor_reading( start_time: float, data_queue: Queue, current_reading: AtomicValue, gps_value: AtomicValue, altimeter_value: AtomicValue, magnetometer_accelerometer_value: AtomicValue, ) -> float: """Grab the latest values from all sensors and put the data in the queue and atomic store""" now = time.time() info = ( now - start_time, *altimeter_value.get_value(), *magnetometer_accelerometer_value.get_value(), *gps_value.get_value(), ) data_queue.put(info) current_reading.try_update(info) return now