From b13b77e42f26b08f157e7aac440377c70915aa8a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 25 Oct 2014 11:34:09 +0800 Subject: [PATCH] pc_rpc: factor WaitQuit code --- artiq/management/pc_rpc.py | 12 ++++++++++++ frontend/artiqd | 13 +++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/artiq/management/pc_rpc.py b/artiq/management/pc_rpc.py index a00c7cbcb..92e31ef2a 100644 --- a/artiq/management/pc_rpc.py +++ b/artiq/management/pc_rpc.py @@ -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() diff --git a/frontend/artiqd b/frontend/artiqd index c257fb09a..8fe175fbd 100755 --- a/frontend/artiqd +++ b/frontend/artiqd @@ -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)