From 08f2aa8503892648317fc0a0a03025d6ef54669a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 9 Dec 2014 16:26:50 +0800 Subject: [PATCH] management/scheduler: replace queue with transparent list + semaphore --- artiq/management/scheduler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/artiq/management/scheduler.py b/artiq/management/scheduler.py index 775b14c19..c415ecc0e 100644 --- a/artiq/management/scheduler.py +++ b/artiq/management/scheduler.py @@ -6,7 +6,8 @@ from artiq.management.worker import Worker class Scheduler: def __init__(self, *args, **kwargs): self.worker = Worker(*args, **kwargs) - self.queue = asyncio.Queue() + self.queued = [] + self.queue_count = asyncio.Semaphore(0) @asyncio.coroutine def start(self): @@ -21,11 +22,13 @@ class Scheduler: yield from self.worker.end_process() def run_once(self, run_params, timeout): - self.queue.put_nowait((run_params, timeout)) + self.queued.append((run_params, timeout)) + self.queue_count.release() @asyncio.coroutine def _schedule(self): while True: - run_params, timeout = yield from self.queue.get() + yield from self.queue_count.acquire() + run_params, timeout = self.queued.pop(0) result = yield from self.worker.run(run_params, timeout) print(result)