diff --git a/.github/workflows/python-pytest.yml b/.github/workflows/python-pytest.yml index 7cc9631..a6c2c8d 100644 --- a/.github/workflows/python-pytest.yml +++ b/.github/workflows/python-pytest.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 90aa4fe..248920a 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ coverage.xml # vim *.sw? +/.vscode diff --git a/yaqd-core/CHANGELOG.md b/yaqd-core/CHANGELOG.md index 5f8d640..0eb919b 100644 --- a/yaqd-core/CHANGELOG.md +++ b/yaqd-core/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] ### Fixed +- removed asyncio syntax that was removed in python 3.14 - type hints for IsSensor attributes are appropriate for _n_-dimensional data ## [2023.11.0] diff --git a/yaqd-core/yaqd_core/_is_daemon.py b/yaqd-core/yaqd_core/_is_daemon.py old mode 100755 new mode 100644 index c2940fe..0ba6cd7 --- a/yaqd-core/yaqd_core/_is_daemon.py +++ b/yaqd-core/yaqd_core/_is_daemon.py @@ -123,17 +123,7 @@ def _traits(cls) -> List[str]: @classmethod def main(cls): - """Run the event loop.""" - loop = asyncio.get_event_loop() - if sys.platform.startswith("win"): - signals = () - else: - signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT) - for s in signals: - loop.add_signal_handler( - s, lambda s=s: asyncio.create_task(cls.shutdown_all(s, loop)) - ) - + """parse arguments and start the event loop""" parser = argparse.ArgumentParser() parser.add_argument( "--config", @@ -199,19 +189,26 @@ def main(cls): with open(config_filepath, "rb") as f: config_file = tomli.load(f) - loop.create_task(cls._main(config_filepath, config_file, args)) + # Run the event loop try: - loop.run_forever() + asyncio.run(cls._main(config_filepath, config_file, args)) except asyncio.CancelledError: pass - finally: - loop.close() @classmethod async def _main(cls, config_filepath, config_file, args=None): - """Parse command line arguments, start event loop tasks.""" + """Parse command line arguments, run event loop.""" loop = asyncio.get_running_loop() - cls.__servers = [] + if sys.platform.startswith("win"): + signals = () + else: + signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT) + for s in signals: + loop.add_signal_handler( + 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 @@ -225,7 +222,7 @@ async def _main(cls, config_filepath, config_file, args=None): while cls.__servers: awaiting = cls.__servers - cls.__servers = [] + cls.__servers = set() await asyncio.wait(awaiting) await asyncio.sleep(1) loop.stop() @@ -252,7 +249,9 @@ def server(daemon): server(daemon), config.get("host", ""), config.get("port", None) ) daemon._server = ser - cls.__servers.append(asyncio.create_task(ser.serve_forever())) + task = asyncio.create_task(ser.serve_forever()) + cls.__servers.add(task) + task.add_done_callback(cls.__servers.discard) @classmethod def _parse_config(cls, config_file, section, args=None): @@ -297,16 +296,7 @@ async def shutdown_all(cls, sig, loop): # This is done after cancelling so that shutdown tasks which require the loop # are not themselves cancelled. [d.close() for d in cls._daemons] - tasks = [ - t - for t in asyncio.all_tasks() - if ( - t is not asyncio.current_task() - and "serve_forever" not in t.get_coro().__repr__() - ) - ] - for task in tasks: - logger.info(task.get_coro()) + tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()] await asyncio.gather(*tasks, return_exceptions=True) [d._save_state() for d in cls._daemons] if hasattr(signal, "SIGHUP") and sig == signal.SIGHUP: diff --git a/yaqd-core/yaqd_core/_protocol.py b/yaqd-core/yaqd_core/_protocol.py index 6644a08..10bd3fa 100644 --- a/yaqd-core/yaqd_core/_protocol.py +++ b/yaqd-core/yaqd_core/_protocol.py @@ -28,7 +28,7 @@ def connection_made(self, transport): self.transport = transport self.unpacker = avrorpc.Unpacker(self._avro_protocol) self._daemon._connection_made(peername) - self.task = asyncio.get_event_loop().create_task(self.process_requests()) + self.task = asyncio.get_running_loop().create_task(self.process_requests()) def data_received(self, data): """Process an incomming request.""" diff --git a/yaqd-fakes/yaqd_fakes/_fake_sensor.py b/yaqd-fakes/yaqd_fakes/_fake_sensor.py index c56f1b3..1e16845 100644 --- a/yaqd-fakes/yaqd_fakes/_fake_sensor.py +++ b/yaqd-fakes/yaqd_fakes/_fake_sensor.py @@ -28,7 +28,7 @@ def __init__(self, name, config, config_filepath): self._channel_generators[name] = random_walk(min_, max_) else: raise Exception(f"channel kind {kwargs['kind']} not recognized") - asyncio.get_event_loop().create_task(self._update_measurements()) + asyncio.get_running_loop().create_task(self._update_measurements()) async def _update_measurements(self): while True: