From 168dd5f64a2251997f5fbab1c460c12ff557e0ed Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 23 Mar 2016 20:03:54 +0000 Subject: Use wait() and notify(), with timeout to allow ^C Change-Id: Iacaf51caaad668710e3111054396d22480082774 --- gear/client.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/gear/client.py b/gear/client.py index cd21eeb8..b4abc8df 100644 --- a/gear/client.py +++ b/gear/client.py @@ -89,9 +89,9 @@ class SingleBuildController(): self._map_build_graph(self.artifact, update_state) # TODO: move to RQ self.build_started = True - if requests_controller.lock_queue.locked(): + with requests_controller.lock_queue: + requests_controller.lock_queue.notify() print "DEBUG: queque release!" - requests_controller.lock_queue.release() def _map_build_graph(self, artifact, callback, components=[]): """Run callback on each artifact in the build graph and return result. @@ -254,8 +254,7 @@ class RequestsController(): def __init__(self): self.next_id = 1 self.new_request_lock = threading.Lock() - self.lock_queue = threading.Lock() - self.lock_queue.acquire() + self.lock_queue = threading.Condition() self.build_requests = [] self.build_status_lock = threading.Lock() @@ -272,7 +271,7 @@ class RequestsController(): self.build_requests.append(request_data) def queue_if_possible(self): - # TODO: check all of them in a loop? + print "DEBUG: Looking for jobs to queue" for request in self.build_requests: print request['id'] controller = request['controller'] @@ -293,8 +292,9 @@ class RequestsController(): for artifact in artifacts: artifact.state = BUILT print "TO %s: Artifact %s built" % (request['id'],artifact.name) - if self.lock_queue.locked(): - self.lock_queue.release() + + with self.lock_queue: + self.lock_queue.notify() def mark_as_building(self, cache_key): @@ -311,9 +311,8 @@ class RequestsController(): def loop(self): while True: - print "DEBUG: locking queue" - self.lock_queue.acquire() - print "DEBUG locked queue" + with self.lock_queue: + self.lock_queue.wait(20) self.queue_if_possible() request = {} -- cgit v1.2.1