From 57086e2349dd0598e3470dbc31154140d1b411be Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 25 May 2022 14:20:04 +0800 Subject: [PATCH 1/5] flake: update nixpkgs --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 56bcfea39..59a9b221a 100644 --- a/flake.lock +++ b/flake.lock @@ -41,11 +41,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1652559422, - "narHash": "sha256-jPVTNImBTUIFdtur+d4IVot6eXmsvtOcBm0TzxmhWPk=", + "lastModified": 1653087707, + "narHash": "sha256-zfno3snrzZTWQ2B7K53QHrGZwrjnJLTRPalymrSsziU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8b3398bc7587ebb79f93dfeea1b8c574d3c6dba1", + "rev": "cbd40c72b2603ab54e7208f99f9b35fc158bc009", "type": "github" }, "original": { From 18a08954c18192526874c694766a32246b7a5445 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 25 May 2022 15:48:17 +0800 Subject: [PATCH 2/5] flake: update comtools --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 59a9b221a..e3c17de9d 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ ] }, "locked": { - "lastModified": 1649124276, - "narHash": "sha256-l1+vk7cvj4cjl83wRx/y1Jwdds4e8xAzpxHrXusEZ5A=", + "lastModified": 1653464839, + "narHash": "sha256-v8opJPrCfZBH6zsnskTPUCeWYvYnyiIc8I/DWv5OrHE=", "owner": "m-labs", "repo": "artiq-comtools", - "rev": "e2d85f2e51ecdac463da752ef754e59572f9e119", + "rev": "00e15e85cf4255e1462b2cc73f4e55590c826f85", "type": "github" }, "original": { From d4780861196fe1e7a800270514b5592a7ead3689 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 26 May 2022 12:00:40 +0800 Subject: [PATCH 3/5] flake: support impure derivation for HITL test --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index c025214a9..3449f54bb 100644 --- a/flake.nix +++ b/flake.nix @@ -448,8 +448,8 @@ kc705-hitl = pkgs.stdenv.mkDerivation { name = "kc705-hitl"; - # requires patched Nix - __networked = true; + __networked = true; # compatibility with old patched Nix + __impure = true; # Nix 2.8+ buildInputs = [ (pkgs.python3.withPackages(ps: with packages.x86_64-linux; [ artiq ps.paramiko ])) From df1b19082ccc263e137da7917ef9ee48f31ec7c9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 27 May 2022 15:14:11 +0800 Subject: [PATCH 4/5] flake: update dependencies --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index e3c17de9d..cdc6e364d 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ ] }, "locked": { - "lastModified": 1653464839, - "narHash": "sha256-v8opJPrCfZBH6zsnskTPUCeWYvYnyiIc8I/DWv5OrHE=", + "lastModified": 1653635602, + "narHash": "sha256-8Osaeuo5/Yq4sU4mhsIXwmy7ZX3iDBbAAZF3lu1+KdQ=", "owner": "m-labs", "repo": "artiq-comtools", - "rev": "00e15e85cf4255e1462b2cc73f4e55590c826f85", + "rev": "accc6dd0ca1c1c240b906b14c5cb13098a14906b", "type": "github" }, "original": { @@ -41,11 +41,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1653087707, - "narHash": "sha256-zfno3snrzZTWQ2B7K53QHrGZwrjnJLTRPalymrSsziU=", + "lastModified": 1653229824, + "narHash": "sha256-klSCYMpR4TqWYoTD/xZ2qM9UIPRFC6pK+S/kJuVLbFw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "cbd40c72b2603ab54e7208f99f9b35fc158bc009", + "rev": "06db2e2197401b74fcf82d4e84be15b0b5851c7b", "type": "github" }, "original": { @@ -73,11 +73,11 @@ ] }, "locked": { - "lastModified": 1651624017, - "narHash": "sha256-engReD8l4xzQQJP8BJ7gILUyA1KH5d60lexDVfnoiRM=", + "lastModified": 1653633179, + "narHash": "sha256-xyHQ77RXI9Zq9is+9laArq1HnlyubozL+Ht9BEQGXow=", "owner": "m-labs", "repo": "sipyco", - "rev": "efda015e9994faf6cafc19b239d8e69ca4d26226", + "rev": "438f649864c58fa2eb213030a336864bba3a18a8", "type": "github" }, "original": { From 7cff63e5394943b6f59aca5183f39f19d77add11 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 27 May 2022 15:17:27 +0800 Subject: [PATCH 5/5] frontend: use sipyco SignalHandler (#1063) --- artiq/frontend/aqctl_corelog.py | 32 ++++++++++++++++--------- artiq/frontend/aqctl_moninj_proxy.py | 35 +++++++++++++++++----------- artiq/frontend/artiq_master.py | 7 ++++-- artiq/frontend/artiq_rtiomon.py | 25 +++++++++++++------- 4 files changed, 64 insertions(+), 35 deletions(-) diff --git a/artiq/frontend/aqctl_corelog.py b/artiq/frontend/aqctl_corelog.py index 95bbfe023..c86c276d5 100755 --- a/artiq/frontend/aqctl_corelog.py +++ b/artiq/frontend/aqctl_corelog.py @@ -9,6 +9,7 @@ import re from sipyco.pc_rpc import Server from sipyco import common_args from sipyco.logging_tools import log_with_name +from sipyco.asyncio_tools import SignalHandler from artiq.coredevice.comm_mgmt import Request, Reply @@ -77,21 +78,30 @@ def main(): loop = asyncio.get_event_loop() try: - get_logs_task = asyncio.ensure_future( - get_logs_sim(args.core_addr) if args.simulation else get_logs(args.core_addr)) + signal_handler = SignalHandler() + signal_handler.setup() try: - server = Server({"corelog": PingTarget()}, None, True) - loop.run_until_complete(server.start(common_args.bind_address_from_args(args), args.port)) + get_logs_task = asyncio.ensure_future( + get_logs_sim(args.core_addr) if args.simulation else get_logs(args.core_addr)) try: - loop.run_until_complete(server.wait_terminate()) + server = Server({"corelog": PingTarget()}, None, True) + loop.run_until_complete(server.start(common_args.bind_address_from_args(args), args.port)) + try: + _, pending = loop.run_until_complete(asyncio.wait( + [signal_handler.wait_terminate(), server.wait_terminate()], + return_when=asyncio.FIRST_COMPLETED)) + for task in pending: + task.cancel() + finally: + loop.run_until_complete(server.stop()) finally: - loop.run_until_complete(server.stop()) + get_logs_task.cancel() + try: + loop.run_until_complete(get_logs_task) + except asyncio.CancelledError: + pass finally: - get_logs_task.cancel() - try: - loop.run_until_complete(get_logs_task) - except asyncio.CancelledError: - pass + signal_handler.teardown() finally: loop.close() diff --git a/artiq/frontend/aqctl_moninj_proxy.py b/artiq/frontend/aqctl_moninj_proxy.py index 0ce317fba..5d7aca2a3 100755 --- a/artiq/frontend/aqctl_moninj_proxy.py +++ b/artiq/frontend/aqctl_moninj_proxy.py @@ -6,7 +6,7 @@ import asyncio import struct from enum import Enum -from sipyco.asyncio_tools import AsyncioServer +from sipyco.asyncio_tools import AsyncioServer, SignalHandler from sipyco.pc_rpc import Server from sipyco import common_args @@ -198,24 +198,33 @@ def main(): loop = asyncio.get_event_loop() try: - monitor_mux = MonitorMux() - comm_moninj = CommMonInj(monitor_mux.monitor_cb, monitor_mux.injection_status_cb) - monitor_mux.comm_moninj = comm_moninj - loop.run_until_complete(comm_moninj.connect(args.core_addr)) + signal_handler = SignalHandler() + signal_handler.setup() try: - proxy_server = ProxyServer(monitor_mux) - loop.run_until_complete(proxy_server.start(bind_address, args.port_proxy)) + monitor_mux = MonitorMux() + comm_moninj = CommMonInj(monitor_mux.monitor_cb, monitor_mux.injection_status_cb) + monitor_mux.comm_moninj = comm_moninj + loop.run_until_complete(comm_moninj.connect(args.core_addr)) try: - server = Server({"moninj_proxy": PingTarget()}, None, True) - loop.run_until_complete(server.start(bind_address, args.port_control)) + proxy_server = ProxyServer(monitor_mux) + loop.run_until_complete(proxy_server.start(bind_address, args.port_proxy)) try: - loop.run_until_complete(server.wait_terminate()) + server = Server({"moninj_proxy": PingTarget()}, None, True) + loop.run_until_complete(server.start(bind_address, args.port_control)) + try: + _, pending = loop.run_until_complete(asyncio.wait( + [signal_handler.wait_terminate(), server.wait_terminate()], + return_when=asyncio.FIRST_COMPLETED)) + for task in pending: + task.cancel() + finally: + loop.run_until_complete(server.stop()) finally: - loop.run_until_complete(server.stop()) + loop.run_until_complete(proxy_server.stop()) finally: - loop.run_until_complete(proxy_server.stop()) + loop.run_until_complete(comm_moninj.close()) finally: - loop.run_until_complete(comm_moninj.close()) + signal_handler.teardown() finally: loop.close() diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index 83c6615ae..2b8893d07 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -10,7 +10,7 @@ from sipyco.sync_struct import Publisher from sipyco.logging_tools import Server as LoggingServer from sipyco.broadcast import Broadcaster from sipyco import common_args -from sipyco.asyncio_tools import atexit_register_coroutine +from sipyco.asyncio_tools import atexit_register_coroutine, SignalHandler from artiq import __version__ as artiq_version from artiq.master.log import log_args, init_log @@ -76,6 +76,9 @@ def main(): log_forwarder = init_log(args) loop = asyncio.get_event_loop() atexit.register(loop.close) + signal_handler = SignalHandler() + signal_handler.setup() + atexit.register(signal_handler.teardown) bind = common_args.bind_address_from_args(args) server_broadcast = Broadcaster() @@ -155,7 +158,7 @@ def main(): atexit_register_coroutine(server_logging.stop) print("ARTIQ master is now ready.") - loop.run_forever() + loop.run_until_complete(signal_handler.wait_terminate()) if __name__ == "__main__": main() diff --git a/artiq/frontend/artiq_rtiomon.py b/artiq/frontend/artiq_rtiomon.py index eed6a9074..8649f8d5f 100755 --- a/artiq/frontend/artiq_rtiomon.py +++ b/artiq/frontend/artiq_rtiomon.py @@ -3,6 +3,8 @@ import argparse import asyncio +from sipyco.asyncio_tools import SignalHandler + from artiq.coredevice.comm_moninj import * @@ -18,19 +20,24 @@ def get_argparser(): def main(): args = get_argparser().parse_args() - + loop = asyncio.get_event_loop() try: - comm = CommMonInj( - lambda channel, probe, value: print("0x{:06x}: {}".format(channel, value)), - lambda channel, override, value: None) - loop.run_until_complete(comm.connect(args.core_addr)) + signal_handler = SignalHandler() + signal_handler.setup() try: - for channel in args.channel: - comm.monitor_probe(True, channel, 0) - loop.run_forever() + comm = CommMonInj( + lambda channel, probe, value: print("0x{:06x}: {}".format(channel, value)), + lambda channel, override, value: None) + loop.run_until_complete(comm.connect(args.core_addr)) + try: + for channel in args.channel: + comm.monitor_probe(True, channel, 0) + loop.run_until_complete(signal_handler.wait_terminate()) + finally: + loop.run_until_complete(comm.close()) finally: - loop.run_until_complete(comm.close()) + signal_handler.teardown() finally: loop.close()