X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=blobdiff_plain;f=processor.py;h=0ad86ff8cd7369c4623c0abd4d71a36cb20a1bd3;hp=baec5d085dd6fa5048a0d1d50cfbbb51f7d83196;hb=f4375ead502d52f5f1e4df8e9b2cc63762326722;hpb=c9c337a89a3f04d7a985a521ca552d421fd94fda diff --git a/processor.py b/processor.py index baec5d0..0ad86ff 100644 --- a/processor.py +++ b/processor.py @@ -83,6 +83,7 @@ class RequestDispatcher(threading.Thread): self.internal_ids = {} self.internal_id = 1 self.lock = threading.Lock() + self.idlock = threading.Lock() self.sessions = [] self.processors = {} @@ -104,11 +105,11 @@ class RequestDispatcher(threading.Thread): return x def get_session_id(self, internal_id): - with self.lock: + with self.idlock: return self.internal_ids.pop(internal_id) def store_session_id(self, session, msgid): - with self.lock: + with self.idlock: self.internal_ids[self.internal_id] = session, msgid r = self.internal_id self.internal_id += 1 @@ -137,7 +138,6 @@ class RequestDispatcher(threading.Thread): suffix = method.split('.')[-1] if session is not None: - is_new = session.protocol_version >= 0.5 if suffix == 'subscribe': session.subscribe_to_service(method, params) @@ -160,9 +160,6 @@ class RequestDispatcher(threading.Thread): except: pass - #if session.protocol_version < 0.6: - # print_log("stopping session from old client", session.protocol_version) - # session.stop() def get_sessions(self): with self.lock: @@ -175,15 +172,26 @@ class RequestDispatcher(threading.Thread): def collect_garbage(self): # Deep copy entire sessions list and blank it - # This is done to minimise lock contention + # This is done to minimize lock contention with self.lock: sessions = self.sessions[:] - self.sessions = [] + + active_sessions = [] + + now = time.time() + for session in sessions: + if (now - session.time) > 1000: + session.stop() + for session in sessions: if not session.stopped(): # If session is still alive then re-add it back # to our internal register - self.add_session(session) + active_sessions.append(session) + + with self.lock: + self.sessions = active_sessions[:] + class Session: