forked from M-Labs/artiq
management/scheduler: replace queue with transparent list + semaphore
This commit is contained in:
parent
059608d1fd
commit
08f2aa8503
@ -6,7 +6,8 @@ from artiq.management.worker import Worker
|
|||||||
class Scheduler:
|
class Scheduler:
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.worker = Worker(*args, **kwargs)
|
self.worker = Worker(*args, **kwargs)
|
||||||
self.queue = asyncio.Queue()
|
self.queued = []
|
||||||
|
self.queue_count = asyncio.Semaphore(0)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self):
|
def start(self):
|
||||||
@ -21,11 +22,13 @@ class Scheduler:
|
|||||||
yield from self.worker.end_process()
|
yield from self.worker.end_process()
|
||||||
|
|
||||||
def run_once(self, run_params, timeout):
|
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
|
@asyncio.coroutine
|
||||||
def _schedule(self):
|
def _schedule(self):
|
||||||
while True:
|
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)
|
result = yield from self.worker.run(run_params, timeout)
|
||||||
print(result)
|
print(result)
|
||||||
|
Loading…
Reference in New Issue
Block a user