2014-10-05 16:25:31 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
2014-10-23 18:48:03 +08:00
|
|
|
from artiq.management.pc_rpc import Server
|
2014-10-05 16:25:31 +08:00
|
|
|
from artiq.management.scheduler import Scheduler
|
|
|
|
|
|
|
|
|
2014-10-23 18:48:03 +08:00
|
|
|
class Master:
|
|
|
|
def __init__(self, scheduler):
|
2014-10-05 16:25:31 +08:00
|
|
|
self.scheduler = scheduler
|
|
|
|
self.terminate_notify = asyncio.Semaphore(0)
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2014-10-23 18:48:03 +08:00
|
|
|
def wait_quit(self):
|
2014-10-05 16:25:31 +08:00
|
|
|
yield from self.terminate_notify.acquire()
|
2014-10-23 18:48:03 +08:00
|
|
|
|
|
|
|
def quit(self):
|
|
|
|
self.terminate_notify.release()
|
|
|
|
|
|
|
|
def run_once(self, run_params, timeout):
|
|
|
|
self.scheduler.run_once(run_params, timeout)
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
try:
|
2014-10-23 18:48:03 +08:00
|
|
|
scheduler = Scheduler()
|
|
|
|
loop.run_until_complete(scheduler.start())
|
|
|
|
try:
|
|
|
|
master = Master(scheduler)
|
|
|
|
server = Server(master)
|
|
|
|
loop.run_until_complete(server.start("::1", 8888))
|
|
|
|
try:
|
|
|
|
loop.run_until_complete(master.wait_quit())
|
|
|
|
finally:
|
|
|
|
loop.run_until_complete(server.stop())
|
|
|
|
finally:
|
|
|
|
loop.run_until_complete(scheduler.stop())
|
2014-10-05 16:25:31 +08:00
|
|
|
finally:
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|