Skip to content

Commit

Permalink
management/scheduler: replace queue with transparent list + semaphore
Browse files Browse the repository at this point in the history
sbourdeauducq committed Dec 9, 2014
1 parent 059608d commit 08f2aa8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions artiq/management/scheduler.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@
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 @@ def stop(self):
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)

0 comments on commit 08f2aa8

Please sign in to comment.