From 3e896ee09b272e083cdea4aa8b9465b1b7758782 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 4 Nov 2019 11:19:25 +0000 Subject: [PATCH] Remove inactive follower threads --- daemon.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/daemon.py b/daemon.py index f69747c1..d4d28ba0 100644 --- a/daemon.py +++ b/daemon.py @@ -468,6 +468,14 @@ class PubServer(BaseHTTPRequestHandler): createSession(self.server.domain,self.server.port,self.server.useTor) if self.server.debug: print('DEBUG: sending c2s post to followers') + # remove inactive threads + inactiveFollowerThreads=[] + for th in self.server.followersThreads: + if not th.is_alive(): + inactiveFollowerThreads.append(th) + for th in inactiveFollowerThreads: + self.server.followersThreads.remove(th) + # create a thread to send the post to followers followersThread= \ sendToFollowersThread(self.server.session, \ self.server.baseDir, \ @@ -486,6 +494,10 @@ class PubServer(BaseHTTPRequestHandler): # retain up to 10 threads if len(self.server.followersThreads)>10: for i in range(2): + # kill the thread if it is still alive + if self.server.followersThreads[0].is_alive(): + self.server.followersThreads[0].kill() + # remove it from the list self.server.followersThreads.pop(0) if self.server.debug: print('DEBUG: handle any unfollow requests')