forked from M-Labs/artiq
1
0
Fork 0

master: handle logging while scanning repository

This commit is contained in:
Sebastien Bourdeauducq 2015-07-23 23:06:15 +08:00
parent aa2acb9137
commit 3a06e22b67
2 changed files with 6 additions and 5 deletions

View File

@ -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({

View File

@ -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