pc_rpc: remove WaitQuit (use e.g. Ctrl-C on the controller side instead)

This commit is contained in:
Sebastien Bourdeauducq 2014-10-27 14:33:45 +08:00
parent ea37274c09
commit 171ed70f2a
6 changed files with 16 additions and 60 deletions

View File

@ -19,9 +19,6 @@ def _get_args():
help="hostname or IP of the master to connect to") help="hostname or IP of the master to connect to")
parser.add_argument("--port", default=8889, type=int, parser.add_argument("--port", default=8889, type=int,
help="TCP port to use to connect to the master") 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, parser.add_argument("-c", "--channel", default=0, type=int,
help="channel: 3*board_num+dac_num [%(default)s]") help="channel: 3*board_num+dac_num [%(default)s]")
parser.add_argument("-f", "--frame", default=0, type=int, parser.add_argument("-f", "--frame", default=0, type=int,
@ -58,9 +55,6 @@ def _get_args():
def _main(): def _main():
args = _get_args() args = _get_args()
dev = Client(args.server, args.port) dev = Client(args.server, args.port)
if args.quit_controller:
dev.quit()
return
dev.init() dev.init()
if args.reset: if args.reset:

View File

@ -10,7 +10,7 @@ import asyncio
from scipy import interpolate from scipy import interpolate
import numpy as np import numpy as np
from artiq.management.pc_rpc import Server, WaitQuit from artiq.management.pc_rpc import Server
logger = logging.getLogger("Pdq2") logger = logging.getLogger("Pdq2")
@ -83,7 +83,7 @@ if Ftdi is None:
Ftdi = FileFtdi Ftdi = FileFtdi
class Pdq2(WaitQuit): class Pdq2:
""" """
PDQ DAC (a.k.a. QC_Waveform) PDQ DAC (a.k.a. QC_Waveform)
""" """
@ -102,7 +102,6 @@ class Pdq2(WaitQuit):
} }
def __init__(self, serial=None): def __init__(self, serial=None):
WaitQuit.__init__(self)
self.serial = serial self.serial = serial
self.dev = Ftdi(serial) self.dev = Ftdi(serial)
@ -363,9 +362,9 @@ def main():
server = Server(dev) server = Server(dev)
loop.run_until_complete(server.start(args.bind, args.port)) loop.run_until_complete(server.start(args.bind, args.port))
try: try:
loop.run_until_complete(dev.wait_quit()) loop.run_forever()
finally: finally:
loop.run_until_complete(server.stop()) loop.run_until_complete(server.stop())
finally: finally:
loop.close() loop.close()
finally: finally:

View File

@ -158,31 +158,3 @@ class Server:
writer.write(line.encode()) writer.write(line.encode())
finally: finally:
writer.close() 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()

View File

@ -17,10 +17,6 @@ def _get_args():
"-o", "--run-once", default=[], nargs=3, "-o", "--run-once", default=[], nargs=3,
action="append", action="append",
help="run experiment once. arguments: <path> <name> <timeout>") help="run experiment once. arguments: <path> <name> <timeout>")
parser.add_argument(
"-q", "--quit-master", default=False,
action="store_true",
help="causes the master to quit")
return parser.parse_args() return parser.parse_args()
@ -34,8 +30,6 @@ def main():
"path": path, "path": path,
"name": name "name": name
}, int(timeout)) }, int(timeout))
if args.quit_master:
remote.quit()
finally: finally:
remote.close_rpc() remote.close_rpc()

View File

@ -3,19 +3,10 @@
import asyncio import asyncio
import argparse import argparse
from artiq.management.pc_rpc import Server, WaitQuit from artiq.management.pc_rpc import Server
from artiq.management.scheduler import Scheduler 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(): def _get_args():
parser = argparse.ArgumentParser(description="PDQ2 controller") parser = argparse.ArgumentParser(description="PDQ2 controller")
parser.add_argument( parser.add_argument(
@ -34,11 +25,10 @@ def main():
scheduler = Scheduler() scheduler = Scheduler()
loop.run_until_complete(scheduler.start()) loop.run_until_complete(scheduler.start())
try: try:
master = Master(scheduler) server = Server(scheduler)
server = Server(master)
loop.run_until_complete(server.start(args.bind, args.port)) loop.run_until_complete(server.start(args.bind, args.port))
try: try:
loop.run_until_complete(master.wait_quit()) loop.run_forever()
finally: finally:
loop.run_until_complete(server.stop()) loop.run_until_complete(server.stop())
finally: finally:

View File

@ -46,9 +46,16 @@ class RPCCase(unittest.TestCase):
self.assertEqual(test_object, test_object_back) self.assertEqual(test_object, test_object_back)
class Echo(pc_rpc.WaitQuit): class Echo:
def __init__(self): 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): def echo(self, x):
return x return x