artiq/frontend/artiqd

51 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
import asyncio
import argparse
from artiq.management.pc_rpc import Server, WaitQuit
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(
"--bind", default="::1",
help="hostname or IP address to bind to")
parser.add_argument(
"--port", default=8888, type=int,
help="TCP port to listen to")
return parser.parse_args()
def main():
args = _get_args()
loop = asyncio.get_event_loop()
try:
scheduler = Scheduler()
loop.run_until_complete(scheduler.start())
try:
master = Master(scheduler)
server = Server(master)
loop.run_until_complete(server.start(args.bind, args.port))
try:
loop.run_until_complete(master.wait_quit())
finally:
loop.run_until_complete(server.stop())
finally:
loop.run_until_complete(scheduler.stop())
finally:
loop.close()
if __name__ == "__main__":
main()