2014-10-05 16:25:31 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import asyncio
|
2014-10-25 11:34:52 +08:00
|
|
|
import argparse
|
2014-10-05 16:25:31 +08:00
|
|
|
|
2014-10-27 14:33:45 +08:00
|
|
|
from artiq.management.pc_rpc import Server
|
2014-12-28 18:56:26 +08:00
|
|
|
from artiq.management.sync_struct import Publisher
|
2014-10-05 16:25:31 +08:00
|
|
|
from artiq.management.scheduler import Scheduler
|
|
|
|
|
|
|
|
|
2014-10-25 11:34:52 +08:00
|
|
|
def _get_args():
|
2014-12-08 19:22:02 +08:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2014-10-05 16:25:31 +08:00
|
|
|
def main():
|
2014-10-25 11:34:52 +08:00
|
|
|
args = _get_args()
|
2014-10-05 16:25:31 +08:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
try:
|
2014-12-08 19:22:02 +08:00
|
|
|
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-29 18:44:50 +08:00
|
|
|
schedule_notify = Publisher({
|
|
|
|
"queue": scheduler.queue,
|
|
|
|
"periodic": scheduler.periodic
|
|
|
|
})
|
2014-12-28 18:56:26 +08:00
|
|
|
loop.run_until_complete(schedule_notify.start(
|
2014-12-29 18:44:50 +08:00
|
|
|
args.bind, args.port_schedule_notify))
|
2014-12-28 18:56:26 +08:00
|
|
|
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())
|
2014-10-05 16:25:31 +08:00
|
|
|
finally:
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|