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() scheduler.start()
atexit.register(lambda: loop.run_until_complete(scheduler.stop())) atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
repository = Repository() repository = Repository(log.log)
repository.scan_async() repository.scan_async()
server_control = Server({ server_control = Server({

View File

@ -10,13 +10,13 @@ logger = logging.getLogger(__name__)
@asyncio.coroutine @asyncio.coroutine
def _scan_experiments(): def _scan_experiments(log):
r = dict() r = dict()
for f in os.listdir("repository"): for f in os.listdir("repository"):
if f.endswith(".py"): if f.endswith(".py"):
try: try:
full_name = os.path.join("repository", f) full_name = os.path.join("repository", f)
worker = Worker() worker = Worker({"log": lambda message: log("scan", message)})
try: try:
description = yield from worker.examine(full_name) description = yield from worker.examine(full_name)
finally: finally:
@ -52,16 +52,17 @@ def _sync_explist(target, source):
class Repository: class Repository:
def __init__(self): def __init__(self, log_fn):
self.explist = Notifier(dict()) self.explist = Notifier(dict())
self._scanning = False self._scanning = False
self.log_fn = log_fn
@asyncio.coroutine @asyncio.coroutine
def scan(self): def scan(self):
if self._scanning: if self._scanning:
return return
self._scanning = True self._scanning = True
new_explist = yield from _scan_experiments() new_explist = yield from _scan_experiments(self.log_fn)
_sync_explist(self.explist, new_explist) _sync_explist(self.explist, new_explist)
self._scanning = False self._scanning = False