From 606e7841fd6040c51592cb34e2c6b1d8cfee8654 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 3 Sep 2019 20:40:44 +0100 Subject: [PATCH] One outbox thread per child --- daemon.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/daemon.py b/daemon.py index 1f020191e..dc82e7a87 100644 --- a/daemon.py +++ b/daemon.py @@ -428,21 +428,25 @@ class PubServer(BaseHTTPRequestHandler): def _postToOutboxThread(self,messageJson: {}) -> bool: """Creates a thread to send a post """ - if self.server.outboxThread: + accountOutboxThreadName=self.postToNickname + if not accountOutboxThreadName: + accountOutboxThreadName='*' + + if self.server.outboxThread.get(accountOutboxThreadName): print('Waiting for previous outbox thread to end') waitCtr=0 - while self.server.outboxThread.isAlive() and waitCtr<5: + while self.server.outboxThread[accountOutboxThreadName].isAlive() and waitCtr<8: time.sleep(1) waitCtr+=1 - if waitCtr>=5: - self.server.outboxThread.kill() + if waitCtr>=8: + self.server.outboxThread[accountOutboxThreadName].kill() print('Creating outbox thread') - self.server.outboxThread= \ + self.server.outboxThread[accountOutboxThreadName]= \ threadWithTrace(target=self._postToOutbox, \ args=(messageJson.copy(),__version__),daemon=True) print('Starting outbox thread') - self.server.outboxThread.start() + self.server.outboxThread[accountOutboxThreadName].start() return True def _inboxQueueCleardown(self): @@ -3312,7 +3316,7 @@ def runDaemon(projectVersion, \ httpd = ThreadingHTTPServer(serverAddress, PubServerUnitTest) else: httpd = ThreadingHTTPServer(serverAddress, PubServer) - httpd.outboxThread=None + httpd.outboxThread={} httpd.projectVersion=projectVersion # max POST size of 30M httpd.maxPostLength=1024*1024*30