def completed(future: concurrent.futures.Future) -> None: try: data = future.result() except concurrent.futures.CancelledError: logger.debug(f"{cls.__name__} cancelled") except Exception as exc: logger.exception(f"{cls.__name__} errored with: {exc}") else: logger.debug(f"{cls.__name__} completed with: {data}")
async def collect_proximity_data_loop(robot: anki_vector.robot.Robot, future: concurrent.futures.Future, state: MapState): try: scan_interval = 1.0 / PROXIMITY_SCAN_SAMPLE_FREQUENCY_HZ # Runs until the collection_active flag is cleared. # This flag is cleared external to this function. while state.collection_active: # Collect proximity data from the sensor. reading = robot.proximity.last_sensor_reading if reading is not None: await analyze_proximity_sample(reading, robot, state) await asyncio.sleep(scan_interval) # Exceptions raised in this process are ignored, unless we set them on the future, and then run future.result() at a later time except Exception as e: # pylint: disable=broad-except future.set_exception(e) finally: future.set_result(state)
def on_done(weakwindow: 'ElectrumWindow', future: concurrent.futures.Future) -> None: nonlocal format, done_signal try: data = future.result() except concurrent.futures.CancelledError: done_signal.emit(format, None) except Exception as exc: weakwindow.on_exception(exc) else: done_signal.emit(format, data)