diff --git a/yaqd-core/yaqd_core/_is_daemon.py b/yaqd-core/yaqd_core/_is_daemon.py index 0ba6cd7..99328a4 100644 --- a/yaqd-core/yaqd_core/_is_daemon.py +++ b/yaqd-core/yaqd_core/_is_daemon.py @@ -192,13 +192,14 @@ def main(cls): # Run the event loop try: asyncio.run(cls._main(config_filepath, config_file, args)) - except asyncio.CancelledError: - pass + except KeyboardInterrupt: + asyncio.run(cls.shutdown_all(signal.SIGINT, loop=cls.loop)) @classmethod async def _main(cls, config_filepath, config_file, args=None): """Parse command line arguments, run event loop.""" loop = asyncio.get_running_loop() + cls.loop = loop if sys.platform.startswith("win"): signals = () else: diff --git a/yaqd-fakes/yaqd_fakes/_fake_sensor.py b/yaqd-fakes/yaqd_fakes/_fake_sensor.py index 1e16845..b2e0b0d 100644 --- a/yaqd-fakes/yaqd_fakes/_fake_sensor.py +++ b/yaqd-fakes/yaqd_fakes/_fake_sensor.py @@ -39,3 +39,10 @@ async def _update_measurements(self): out["measurement_id"] = self._measurement_id self._measured = out await asyncio.sleep(self._config["update_period"]) + + async def aclose(self): + await asyncio.sleep(0.1) + self.logger.info("finished async close routine") + + def close(self): + asyncio.get_running_loop().create_task(self.aclose())