From 268a099f87daaf9ec6f7024e0d54f82a7a8f29df Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 29 Jan 2014 16:48:00 +0100 Subject: [PATCH] sync_get --- lib/interface.py | 16 ++++++++++++++++ lib/network.py | 16 ++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/interface.py b/lib/interface.py index c82174749..cbcfeff87 100644 --- a/lib/interface.py +++ b/lib/interface.py @@ -598,6 +598,22 @@ class Interface(threading.Thread): self.queue.put(self) + def synchronous_get(self, requests, timeout=100000000): + queue = Queue.Queue() + ids = self.send(requests, lambda i,r: queue.put(r)) + id2 = ids[:] + res = {} + while ids: + r = queue.get(True, timeout) + _id = r.get('id') + if _id in ids: + ids.remove(_id) + res[_id] = r.get('result') + out = [] + for _id in id2: + out.append(res[_id]) + return out + if __name__ == "__main__": diff --git a/lib/network.py b/lib/network.py index d83b00d12..c590d2690 100644 --- a/lib/network.py +++ b/lib/network.py @@ -368,20 +368,8 @@ class Network(threading.Thread): def synchronous_get(self, requests, timeout=100000000): - queue = Queue.Queue() - ids = self.interface.send(requests, lambda i,r: queue.put(r)) - id2 = ids[:] - res = {} - while ids: - r = queue.get(True, timeout) - _id = r.get('id') - if _id in ids: - ids.remove(_id) - res[_id] = r.get('result') - out = [] - for _id in id2: - out.append(res[_id]) - return out + return self.interface.synchronous_get(requests) + #def retrieve_transaction(self, tx_hash, tx_height=0):