2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-19 00:16:29 +08:00

master: add terminate API

This commit is contained in:
Egor Savkin 2023-04-18 15:03:06 +08:00 committed by GitHub
parent 918d30b900
commit aed47d79ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -125,6 +125,9 @@ def get_argparser():
"ls", help="list a directory on the master") "ls", help="list a directory on the master")
parser_ls.add_argument("directory", default="", nargs="?") parser_ls.add_argument("directory", default="", nargs="?")
subparsers.add_parser(
"terminate", help="terminate the ARTIQ master")
common_args.verbosity_args(parser) common_args.verbosity_args(parser)
return parser return parser
@ -195,6 +198,10 @@ def _action_ls(remote, args):
print(name) print(name)
def _action_terminate(remote, _args):
remote.terminate()
def _show_schedule(schedule): def _show_schedule(schedule):
clear_screen() clear_screen()
if schedule: if schedule:
@ -319,7 +326,8 @@ def main():
"del_dataset": "master_dataset_db", "del_dataset": "master_dataset_db",
"scan_devices": "master_device_db", "scan_devices": "master_device_db",
"scan_repository": "master_experiment_db", "scan_repository": "master_experiment_db",
"ls": "master_experiment_db" "ls": "master_experiment_db",
"terminate": "master_terminate",
}[action] }[action]
remote = Client(args.server, port, target_name) remote = Client(args.server, port, target_name)
try: try:

View File

@ -4,6 +4,7 @@ import asyncio
import argparse import argparse
import atexit import atexit
import logging import logging
from types import SimpleNamespace
from sipyco.pc_rpc import Server as RPCServer from sipyco.pc_rpc import Server as RPCServer
from sipyco.sync_struct import Publisher from sipyco.sync_struct import Publisher
@ -133,12 +134,16 @@ def main():
}) })
experiment_db.scan_repository_async(loop=loop) 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({ server_control = RPCServer({
"master_config": config, "master_config": config,
"master_device_db": device_db, "master_device_db": device_db,
"master_dataset_db": dataset_db, "master_dataset_db": dataset_db,
"master_schedule": scheduler, "master_schedule": scheduler,
"master_experiment_db": experiment_db "master_experiment_db": experiment_db,
"master_terminate": master_terminate
}, allow_parallel=True) }, allow_parallel=True)
loop.run_until_complete(server_control.start( loop.run_until_complete(server_control.start(
bind, args.port_control)) bind, args.port_control))
@ -161,7 +166,11 @@ def main():
atexit_register_coroutine(server_logging.stop, loop=loop) atexit_register_coroutine(server_logging.stop, loop=loop)
print("ARTIQ master is now ready.") 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__": if __name__ == "__main__":
main() main()

6
flake.lock generated
View File

@ -89,11 +89,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1673433867, "lastModified": 1681290481,
"narHash": "sha256-a7Oq35YoDzPtISbqAsaT+2/v15HZ7G1q0ukXmKWdb7Q=", "narHash": "sha256-VEZcGhbtJGonRrrWi31evNDVSerlLjEPL0MZGm9VlB8=",
"owner": "m-labs", "owner": "m-labs",
"repo": "sipyco", "repo": "sipyco",
"rev": "38f8f4185d7db6b68bd7f71546da9077b1e2561c", "rev": "727631ada6e59dc6ef0ad50bfcc376d2ffe805aa",
"type": "github" "type": "github"
}, },
"original": { "original": {