summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-23 20:03:54 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-27 11:53:02 +0000
commit168dd5f64a2251997f5fbab1c460c12ff557e0ed (patch)
tree80f88cf3941ff896a33101b7d36b16b810de2e5c
parentb500ae772f301166b61181351294fda2be4e590f (diff)
downloadmorph-168dd5f64a2251997f5fbab1c460c12ff557e0ed.tar.gz
Use wait() and notify(), with timeout to allow ^C
Change-Id: Iacaf51caaad668710e3111054396d22480082774
-rw-r--r--gear/client.py19
1 files 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 = {}