From 3a06e22b67fa81e5ecbbbd86db1b31c0c40d8c2c Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 23 Jul 2015 23:06:15 +0800 Subject: [PATCH] master: handle logging while scanning repository --- artiq/frontend/artiq_master.py | 2 +- artiq/master/repository.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index 6f7840cda..01c3fb081 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -69,7 +69,7 @@ def main(): scheduler.start() atexit.register(lambda: loop.run_until_complete(scheduler.stop())) - repository = Repository() + repository = Repository(log.log) repository.scan_async() server_control = Server({ diff --git a/artiq/master/repository.py b/artiq/master/repository.py index 3e5e2a783..465ce6f85 100644 --- a/artiq/master/repository.py +++ b/artiq/master/repository.py @@ -10,13 +10,13 @@ logger = logging.getLogger(__name__) @asyncio.coroutine -def _scan_experiments(): +def _scan_experiments(log): r = dict() for f in os.listdir("repository"): if f.endswith(".py"): try: full_name = os.path.join("repository", f) - worker = Worker() + worker = Worker({"log": lambda message: log("scan", message)}) try: description = yield from worker.examine(full_name) finally: @@ -52,16 +52,17 @@ def _sync_explist(target, source): class Repository: - def __init__(self): + def __init__(self, log_fn): self.explist = Notifier(dict()) self._scanning = False + self.log_fn = log_fn @asyncio.coroutine def scan(self): if self._scanning: return self._scanning = True - new_explist = yield from _scan_experiments() + new_explist = yield from _scan_experiments(self.log_fn) _sync_explist(self.explist, new_explist) self._scanning = False