From ac6403ee0964644e1afe3f5df2daaf668a0ef261 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 18 Apr 2013 13:13:13 +0400 Subject: [PATCH] fix possible race condition in collect_gargage --- processor.py | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/processor.py b/processor.py index baec5d0..71b9d62 100644 --- a/processor.py +++ b/processor.py @@ -175,15 +175,20 @@ 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 = [] 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: -- 1.7.1