tfollow-up to bd781d600b8ce2bc9dcebebbdb0fb60ad2fb892e: use pipe - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 5bd22d237858353c4f1b35ea1887f2524752b85a (DIR) parent 5841f943e89de825a50fadbcd123a3620fe7ad70 (HTM) Author: ThomasV <thomasv@gitorious> Date: Thu, 21 May 2015 12:50:26 +0200 follow-up to bd781d600b8ce2bc9dcebebbdb0fb60ad2fb892e: use pipe Diffstat: M lib/daemon.py | 19 +++++-------------- M lib/network.py | 6 +++--- M lib/network_proxy.py | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) --- (DIR) diff --git a/lib/daemon.py b/lib/daemon.py t@@ -117,14 +117,9 @@ class NetworkServer(util.DaemonThread): util.DaemonThread.__init__(self) self.debug = False self.config = config - # network sends responses on that queue - self.network_queue = Queue.Queue() - self.requests_queue = Queue.Queue() - self.network = Network(self.requests_queue, self.network_queue, config) - - self.running = False + self.pipe = util.QueuePipe() + self.network = Network(self.pipe, config) self.lock = threading.RLock() - # each GUI is a client of the daemon self.clients = [] self.request_id = 0 t@@ -148,18 +143,16 @@ class NetworkServer(util.DaemonThread): self.request_id += 1 self.requests[self.request_id] = (request['id'], client) request['id'] = self.request_id - if self.debug: print_error("-->", request) - self.requests_queue.put(request) - + self.pipe.send(request) def run(self): self.network.start() while self.is_running(): try: - response = self.network_queue.get(timeout=0.1) - except Queue.Empty: + response = self.pipe.get() + except util.timeout: continue if self.debug: print_error("<--", response) t@@ -176,12 +169,10 @@ class NetworkServer(util.DaemonThread): for client in self.clients: if repr((m, v)) in client.subscriptions: client.response_queue.put(response) - self.network.stop() print_error("server exiting") - def daemon_loop(server): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) (DIR) diff --git a/lib/network.py b/lib/network.py t@@ -123,7 +123,7 @@ def serialize_server(host, port, protocol): class Network(util.DaemonThread): - def __init__(self, requests_queue, response_queue, config=None): + def __init__(self, pipe, config=None): if config is None: config = {} # Do not use mutables as default values! util.DaemonThread.__init__(self) t@@ -132,8 +132,8 @@ class Network(util.DaemonThread): self.blockchain = Blockchain(self.config, self) self.interfaces = {} self.queue = Queue.Queue() - self.requests_queue = requests_queue - self.response_queue = response_queue + self.requests_queue = pipe.send_queue + self.response_queue = pipe.get_queue # Server for addresses and transactions self.default_server = self.config.get('server') # Sanitize default server (DIR) diff --git a/lib/network_proxy.py b/lib/network_proxy.py t@@ -55,7 +55,7 @@ class NetworkProxy(util.DaemonThread): self.network = None else: self.pipe = util.QueuePipe() - self.network = Network(self.pipe.send_queue, self.pipe.get_queue, config) + self.network = Network(self.pipe, config) self.network.start() for key in ['status','banner','updated','servers','interfaces']: value = self.network.get_status_value(key)