commit 107cfc058de3d0f2d76468ff4b87166f1a09d386
parent 18032fc4f67cf405dc5912084f17b3dd3f890263
Author: ThomasV <electrumdev@gmail.com>
Date: Tue, 19 May 2015 10:18:08 +0200
Merge pull request #1216 from kyuupichan/network-unthread
No need for thread to handle requests
Diffstat:
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/lib/network.py b/lib/network.py
@@ -1,4 +1,3 @@
-import threading
import time
import Queue
import os
@@ -129,7 +128,6 @@ class Network(util.DaemonThread):
config = {} # Do not use mutables as default values!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
- self.lock = threading.Lock()
self.num_server = 8 if not self.config.get('oneserver') else 0
self.blockchain = Blockchain(self.config, self)
self.interfaces = {}
@@ -303,8 +301,6 @@ class Network(util.DaemonThread):
self.running = True
self.response_queue = response_queue
self.start_interfaces()
- t = threading.Thread(target=self.process_requests_thread)
- t.start()
self.blockchain.start()
util.DaemonThread.start(self)
@@ -433,13 +429,12 @@ class Network(util.DaemonThread):
else:
self.response_queue.put(response)
- def process_requests_thread(self):
- while self.is_running():
- try:
- request = self.requests_queue.get(timeout=0.1)
- except Queue.Empty:
- continue
- self.process_request(request)
+ def handle_requests(self):
+ try:
+ request = self.requests_queue.get(timeout=0.1)
+ except Queue.Empty:
+ return
+ self.process_request(request)
def process_request(self, request):
method = request['method']
@@ -470,14 +465,7 @@ class Network(util.DaemonThread):
# store unanswered request
self.unanswered_requests[_id] = request
-
- try:
- self.interface.send_request(request)
- except:
- # put it back in the queue
- self.print_error("warning: interface not ready for", request)
- self.requests_queue.put(request)
- time.sleep(0.1)
+ self.interface.send_request(request)
def check_interfaces(self):
now = time.time()
@@ -509,6 +497,7 @@ class Network(util.DaemonThread):
def run(self):
while self.is_running():
self.check_interfaces()
+ self.handle_requests()
try:
i, response = self.queue.get(timeout=0.1)
except Queue.Empty: