mirror of https://github.com/m-labs/artiq.git
pc_rpc: factor WaitQuit code
This commit is contained in:
parent
513aa393b0
commit
b13b77e42f
|
@ -88,3 +88,15 @@ class Server:
|
||||||
writer.write(line.encode())
|
writer.write(line.encode())
|
||||||
finally:
|
finally:
|
||||||
writer.close()
|
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()
|
||||||
|
|
|
@ -2,21 +2,14 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from artiq.management.pc_rpc import Server
|
from artiq.management.pc_rpc import Server, WaitQuit
|
||||||
from artiq.management.scheduler import Scheduler
|
from artiq.management.scheduler import Scheduler
|
||||||
|
|
||||||
|
|
||||||
class Master:
|
class Master(WaitQuit):
|
||||||
def __init__(self, scheduler):
|
def __init__(self, scheduler):
|
||||||
|
WaitQuit.__init__(self)
|
||||||
self.scheduler = scheduler
|
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):
|
def run_once(self, run_params, timeout):
|
||||||
self.scheduler.run_once(run_params, timeout)
|
self.scheduler.run_once(run_params, timeout)
|
||||||
|
|
Loading…
Reference in New Issue