artiq/frontend/artiq_master.py

52 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import asyncio
2014-10-25 11:34:52 +08:00
import argparse
from artiq.management.pc_rpc import Server
2014-12-28 18:56:26 +08:00
from artiq.management.sync_struct import Publisher
from artiq.management.scheduler import Scheduler
2014-10-25 11:34:52 +08:00
def _get_args():
parser = argparse.ArgumentParser(description="ARTIQ master")
2014-10-25 11:34:52 +08:00
parser.add_argument(
"--bind", default="::1",
help="hostname or IP address to bind to")
parser.add_argument(
2014-12-28 18:56:26 +08:00
"--port-schedule-control", default=8888, type=int,
help="TCP port to listen to for schedule control")
parser.add_argument(
"--port-schedule-notify", default=8887, type=int,
help="TCP port to listen to for schedule notifications")
2014-10-25 11:34:52 +08:00
return parser.parse_args()
def main():
2014-10-25 11:34:52 +08:00
args = _get_args()
loop = asyncio.get_event_loop()
try:
scheduler = Scheduler("ddb.pyon", "pdb.pyon")
2014-10-23 18:48:03 +08:00
loop.run_until_complete(scheduler.start())
try:
2014-12-28 18:56:26 +08:00
schedule_control = Server(scheduler, "schedule_control")
loop.run_until_complete(schedule_control.start(
args.bind, args.port_schedule_control))
2014-10-23 18:48:03 +08:00
try:
2014-12-28 18:56:26 +08:00
schedule_notify = Publisher(scheduler.queued)
loop.run_until_complete(schedule_notify.start(
args.bind, args.port_schedule_notify))
try:
loop.run_forever()
finally:
loop.run_until_complete(schedule_notify.stop())
2014-10-23 18:48:03 +08:00
finally:
2014-12-28 18:56:26 +08:00
loop.run_until_complete(schedule_control.stop())
2014-10-23 18:48:03 +08:00
finally:
loop.run_until_complete(scheduler.stop())
finally:
loop.close()
if __name__ == "__main__":
main()