From 171ed70f2aac3af970a5401ab0dbd1f2321e649e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 27 Oct 2014 14:33:45 +0800 Subject: [PATCH] pc_rpc: remove WaitQuit (use e.g. Ctrl-C on the controller side instead) --- artiq/devices/pdq2/pdq2-client | 6 ------ artiq/devices/pdq2/pdq2-controller | 9 ++++----- artiq/management/pc_rpc.py | 28 ---------------------------- frontend/artiq | 6 ------ frontend/artiqd | 16 +++------------- test/pc_rpc.py | 11 +++++++++-- 6 files changed, 16 insertions(+), 60 deletions(-) diff --git a/artiq/devices/pdq2/pdq2-client b/artiq/devices/pdq2/pdq2-client index 74862383f..4ee1e0c3b 100755 --- a/artiq/devices/pdq2/pdq2-client +++ b/artiq/devices/pdq2/pdq2-client @@ -19,9 +19,6 @@ def _get_args(): help="hostname or IP of the master to connect to") parser.add_argument("--port", default=8889, type=int, help="TCP port to use to connect to the master") - parser.add_argument("-q", "--quit-controller", default=False, - action="store_true", - help="causes the controller to quit") parser.add_argument("-c", "--channel", default=0, type=int, help="channel: 3*board_num+dac_num [%(default)s]") parser.add_argument("-f", "--frame", default=0, type=int, @@ -58,9 +55,6 @@ def _get_args(): def _main(): args = _get_args() dev = Client(args.server, args.port) - if args.quit_controller: - dev.quit() - return dev.init() if args.reset: diff --git a/artiq/devices/pdq2/pdq2-controller b/artiq/devices/pdq2/pdq2-controller index a89f8f14f..10bc71834 100755 --- a/artiq/devices/pdq2/pdq2-controller +++ b/artiq/devices/pdq2/pdq2-controller @@ -10,7 +10,7 @@ import asyncio from scipy import interpolate import numpy as np -from artiq.management.pc_rpc import Server, WaitQuit +from artiq.management.pc_rpc import Server logger = logging.getLogger("Pdq2") @@ -83,7 +83,7 @@ if Ftdi is None: Ftdi = FileFtdi -class Pdq2(WaitQuit): +class Pdq2: """ PDQ DAC (a.k.a. QC_Waveform) """ @@ -102,7 +102,6 @@ class Pdq2(WaitQuit): } def __init__(self, serial=None): - WaitQuit.__init__(self) self.serial = serial self.dev = Ftdi(serial) @@ -363,9 +362,9 @@ def main(): server = Server(dev) loop.run_until_complete(server.start(args.bind, args.port)) try: - loop.run_until_complete(dev.wait_quit()) + loop.run_forever() finally: - loop.run_until_complete(server.stop()) + loop.run_until_complete(server.stop()) finally: loop.close() finally: diff --git a/artiq/management/pc_rpc.py b/artiq/management/pc_rpc.py index c44f307d2..76b5138d9 100644 --- a/artiq/management/pc_rpc.py +++ b/artiq/management/pc_rpc.py @@ -158,31 +158,3 @@ class Server: writer.write(line.encode()) finally: writer.close() - - -class WaitQuit: - """Provides facilities to handle the termination of servers. - - Server targets typically inherit from this class, with the method ``quit`` - called via RPC. - - """ - def __init__(self): - self.terminate_notify = asyncio.Semaphore(0) - - @asyncio.coroutine - def wait_quit(self): - """Waits until the `quit` method is called. This is typically used to - keep the `asyncio` loop running until the server is requested to - terminate. - - This method is a `coroutine`. - - """ - yield from self.terminate_notify.acquire() - - def quit(self): - """Quits the server. - - """ - self.terminate_notify.release() diff --git a/frontend/artiq b/frontend/artiq index b6a3989af..3dd78875f 100755 --- a/frontend/artiq +++ b/frontend/artiq @@ -17,10 +17,6 @@ def _get_args(): "-o", "--run-once", default=[], nargs=3, action="append", help="run experiment once. arguments: ") - parser.add_argument( - "-q", "--quit-master", default=False, - action="store_true", - help="causes the master to quit") return parser.parse_args() @@ -34,8 +30,6 @@ def main(): "path": path, "name": name }, int(timeout)) - if args.quit_master: - remote.quit() finally: remote.close_rpc() diff --git a/frontend/artiqd b/frontend/artiqd index dc83c13e9..ceefd87ca 100755 --- a/frontend/artiqd +++ b/frontend/artiqd @@ -3,19 +3,10 @@ import asyncio import argparse -from artiq.management.pc_rpc import Server, WaitQuit +from artiq.management.pc_rpc import Server from artiq.management.scheduler import Scheduler -class Master(WaitQuit): - def __init__(self, scheduler): - WaitQuit.__init__(self) - self.scheduler = scheduler - - def run_once(self, run_params, timeout): - self.scheduler.run_once(run_params, timeout) - - def _get_args(): parser = argparse.ArgumentParser(description="PDQ2 controller") parser.add_argument( @@ -34,11 +25,10 @@ def main(): scheduler = Scheduler() loop.run_until_complete(scheduler.start()) try: - master = Master(scheduler) - server = Server(master) + server = Server(scheduler) loop.run_until_complete(server.start(args.bind, args.port)) try: - loop.run_until_complete(master.wait_quit()) + loop.run_forever() finally: loop.run_until_complete(server.stop()) finally: diff --git a/test/pc_rpc.py b/test/pc_rpc.py index b6cd4f323..db91086d8 100644 --- a/test/pc_rpc.py +++ b/test/pc_rpc.py @@ -46,9 +46,16 @@ class RPCCase(unittest.TestCase): self.assertEqual(test_object, test_object_back) -class Echo(pc_rpc.WaitQuit): +class Echo: def __init__(self): - pc_rpc.WaitQuit.__init__(self) + self.terminate_notify = asyncio.Semaphore(0) + + @asyncio.coroutine + def wait_quit(self): + yield from self.terminate_notify.acquire() + + def quit(self): + self.terminate_notify.release() def echo(self, x): return x