forked from M-Labs/artiq
1
0
Fork 0

pc_rpc: factor WaitQuit code

This commit is contained in:
Sebastien Bourdeauducq 2014-10-25 11:34:09 +08:00
parent 513aa393b0
commit b13b77e42f
2 changed files with 15 additions and 10 deletions

View File

@ -88,3 +88,15 @@ class Server:
writer.write(line.encode())
finally:
writer.close()
class WaitQuit:
def __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()

View File

@ -2,21 +2,14 @@
import asyncio
from artiq.management.pc_rpc import Server
from artiq.management.pc_rpc import Server, WaitQuit
from artiq.management.scheduler import Scheduler
class Master:
class Master(WaitQuit):
def __init__(self, scheduler):
WaitQuit.__init__(self)
self.scheduler = scheduler
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 run_once(self, run_params, timeout):
self.scheduler.run_once(run_params, timeout)