From 895d02ce62a290b3217686c50cbe831a40504c3b Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 2 May 2026 13:14:08 -0500 Subject: [PATCH 1/2] Update _is_daemon.py --- yaqd-core/yaqd_core/_is_daemon.py | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/yaqd-core/yaqd_core/_is_daemon.py b/yaqd-core/yaqd_core/_is_daemon.py index 0ba6cd7..ee4f597 100644 --- a/yaqd-core/yaqd_core/_is_daemon.py +++ b/yaqd-core/yaqd_core/_is_daemon.py @@ -208,24 +208,27 @@ async def _main(cls, config_filepath, config_file, args=None): s, lambda s=s: asyncio.create_task(cls.shutdown_all(s, loop)) ) - cls.__servers = set() - for section in config_file: - if section == "shared-settings": - continue - try: - config = cls._parse_config(config_file, section, args) - except ValueError as e: - logger.error(str(e)) - continue - logger.debug(f"Starting {section} with {config}") - await cls._start_daemon(section, config, config_filepath) - - while cls.__servers: - awaiting = cls.__servers + try: cls.__servers = set() - await asyncio.wait(awaiting) - await asyncio.sleep(1) - loop.stop() + for section in config_file: + if section == "shared-settings": + continue + try: + config = cls._parse_config(config_file, section, args) + except ValueError as e: + logger.error(str(e)) + continue + logger.debug(f"Starting {section} with {config}") + await cls._start_daemon(section, config, config_filepath) + + while cls.__servers: + awaiting = cls.__servers + cls.__servers = set() + await asyncio.wait(awaiting) + await asyncio.sleep(1) + loop.stop() + except KeyboardInterrupt: # handle windows ctrl+c + await cls.shutdown_all(signal.SIGINT, loop) @classmethod async def _start_daemon(cls, name, config, config_filepath): From 20d93ae040b52ccc4d933d5f4dde4e87945e1075 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 4 May 2026 13:55:23 -0500 Subject: [PATCH 2/2] working with fake-sensor --- yaqd-core/yaqd_core/_is_daemon.py | 42 +++++++++++++-------------- yaqd-fakes/yaqd_fakes/_fake_sensor.py | 7 +++++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/yaqd-core/yaqd_core/_is_daemon.py b/yaqd-core/yaqd_core/_is_daemon.py index ee4f597..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: @@ -208,27 +209,24 @@ async def _main(cls, config_filepath, config_file, args=None): s, lambda s=s: asyncio.create_task(cls.shutdown_all(s, loop)) ) - try: + cls.__servers = set() + for section in config_file: + if section == "shared-settings": + continue + try: + config = cls._parse_config(config_file, section, args) + except ValueError as e: + logger.error(str(e)) + continue + logger.debug(f"Starting {section} with {config}") + await cls._start_daemon(section, config, config_filepath) + + while cls.__servers: + awaiting = cls.__servers cls.__servers = set() - for section in config_file: - if section == "shared-settings": - continue - try: - config = cls._parse_config(config_file, section, args) - except ValueError as e: - logger.error(str(e)) - continue - logger.debug(f"Starting {section} with {config}") - await cls._start_daemon(section, config, config_filepath) - - while cls.__servers: - awaiting = cls.__servers - cls.__servers = set() - await asyncio.wait(awaiting) - await asyncio.sleep(1) - loop.stop() - except KeyboardInterrupt: # handle windows ctrl+c - await cls.shutdown_all(signal.SIGINT, loop) + await asyncio.wait(awaiting) + await asyncio.sleep(1) + loop.stop() @classmethod async def _start_daemon(cls, name, config, config_filepath): 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())