From aed47d79ff9fc63f49d0a3371c16a1c7e6ddcafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=AB=E7=84=9A=20=E5=AF=8C=E8=89=AF?= Date: Tue, 18 Apr 2023 15:03:06 +0800 Subject: [PATCH] master: add terminate API --- artiq/frontend/artiq_client.py | 10 +++++++++- artiq/frontend/artiq_master.py | 13 +++++++++++-- flake.lock | 6 +++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/artiq/frontend/artiq_client.py b/artiq/frontend/artiq_client.py index 8601fed77..03eca3887 100755 --- a/artiq/frontend/artiq_client.py +++ b/artiq/frontend/artiq_client.py @@ -125,6 +125,9 @@ def get_argparser(): "ls", help="list a directory on the master") parser_ls.add_argument("directory", default="", nargs="?") + subparsers.add_parser( + "terminate", help="terminate the ARTIQ master") + common_args.verbosity_args(parser) return parser @@ -195,6 +198,10 @@ def _action_ls(remote, args): print(name) +def _action_terminate(remote, _args): + remote.terminate() + + def _show_schedule(schedule): clear_screen() if schedule: @@ -319,7 +326,8 @@ def main(): "del_dataset": "master_dataset_db", "scan_devices": "master_device_db", "scan_repository": "master_experiment_db", - "ls": "master_experiment_db" + "ls": "master_experiment_db", + "terminate": "master_terminate", }[action] remote = Client(args.server, port, target_name) try: diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index ced3c828c..05959beb5 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -4,6 +4,7 @@ import asyncio import argparse import atexit import logging +from types import SimpleNamespace from sipyco.pc_rpc import Server as RPCServer from sipyco.sync_struct import Publisher @@ -133,12 +134,16 @@ def main(): }) experiment_db.scan_repository_async(loop=loop) + signal_handler_task = loop.create_task(signal_handler.wait_terminate()) + master_terminate = SimpleNamespace(terminate=lambda: signal_handler_task.cancel()) + server_control = RPCServer({ "master_config": config, "master_device_db": device_db, "master_dataset_db": dataset_db, "master_schedule": scheduler, - "master_experiment_db": experiment_db + "master_experiment_db": experiment_db, + "master_terminate": master_terminate }, allow_parallel=True) loop.run_until_complete(server_control.start( bind, args.port_control)) @@ -161,7 +166,11 @@ def main(): atexit_register_coroutine(server_logging.stop, loop=loop) print("ARTIQ master is now ready.") - loop.run_until_complete(signal_handler.wait_terminate()) + try: + loop.run_until_complete(signal_handler_task) + except asyncio.CancelledError: + pass + if __name__ == "__main__": main() diff --git a/flake.lock b/flake.lock index c846559f1..907524a64 100644 --- a/flake.lock +++ b/flake.lock @@ -89,11 +89,11 @@ ] }, "locked": { - "lastModified": 1673433867, - "narHash": "sha256-a7Oq35YoDzPtISbqAsaT+2/v15HZ7G1q0ukXmKWdb7Q=", + "lastModified": 1681290481, + "narHash": "sha256-VEZcGhbtJGonRrrWi31evNDVSerlLjEPL0MZGm9VlB8=", "owner": "m-labs", "repo": "sipyco", - "rev": "38f8f4185d7db6b68bd7f71546da9077b1e2561c", + "rev": "727631ada6e59dc6ef0ad50bfcc376d2ffe805aa", "type": "github" }, "original": {