From 4019814a0566e5271802e6dd185ac7bd4e8da843 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 19 Feb 2020 12:27:21 +0000 Subject: [PATCH] Stop existing threads --- tests.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ threads.py | 8 ++++-- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index a9e066f3e..a94bab3a6 100644 --- a/tests.py +++ b/tests.py @@ -77,6 +77,9 @@ from theme import setCSSparam testServerAliceRunning = False testServerBobRunning = False testServerEveRunning = False +thrAlice=None +thrBob=None +thrEve=None def testHttpsigBase(withDigest): print('testHttpsig(' + str(withDigest) + ')') @@ -361,11 +364,26 @@ def testPostMessageBetweenServers(): aliceSendThreads=[] bobSendThreads=[] + global thrAlice + if thrAlice: + while thrAlice.isAlive(): + thrAlice.stop() + time.sleep(1) + thrAlice.kill() + thrAlice = \ threadWithTrace(target=createServerAlice, \ args=(aliceDir,aliceDomain,alicePort, \ federationList,False,False, \ ocapAlways,aliceSendThreads),daemon=True) + + global thrBob + if thrBob: + while thrBob.isAlive(): + thrBob.stop() + time.sleep(1) + thrBob.kill() + thrBob = \ threadWithTrace(target=createServerBob, \ args=(bobDir,bobDomain,bobPort, \ @@ -556,6 +574,14 @@ def testFollowBetweenServersWithCapabilities(): aliceDomain='127.0.0.42' alicePort=61935 aliceSendThreads=[] + + global thrAlice + if thrAlice: + while thrAlice.isAlive(): + thrAlice.stop() + time.sleep(1) + thrAlice.kill() + thrAlice = \ threadWithTrace(target=createServerAlice, \ args=(aliceDir,aliceDomain,alicePort, \ @@ -566,6 +592,14 @@ def testFollowBetweenServersWithCapabilities(): bobDomain='127.0.0.64' bobPort=61936 bobSendThreads=[] + + global thrBob + if thrBob: + while thrBob.isAlive(): + thrBob.stop() + time.sleep(1) + thrBob.kill() + thrBob = \ threadWithTrace(target=createServerBob, \ args=(bobDir,bobDomain,bobPort, \ @@ -576,6 +610,13 @@ def testFollowBetweenServersWithCapabilities(): eveDomain='127.0.0.55' evePort=61937 eveSendThreads=[] + global thrEve + if thrEve: + while thrEve.isAlive(): + thrEve.stop() + time.sleep(1) + thrEve.kill() + thrEve = \ threadWithTrace(target=createServerEve, \ args=(eveDir,eveDomain,evePort, \ @@ -838,6 +879,14 @@ def testFollowBetweenServers(): aliceDomain='127.0.0.42' alicePort=61935 aliceSendThreads=[] + + global thrAlice + if thrAlice: + while thrAlice.isAlive(): + thrAlice.stop() + time.sleep(1) + thrAlice.kill() + thrAlice = \ threadWithTrace(target=createServerAlice, \ args=(aliceDir,aliceDomain,alicePort, \ @@ -848,6 +897,14 @@ def testFollowBetweenServers(): bobDomain='127.0.0.64' bobPort=61936 bobSendThreads=[] + + global thrBob + if thrBob: + while thrBob.isAlive(): + thrBob.stop() + time.sleep(1) + thrBob.kill() + thrBob = \ threadWithTrace(target=createServerBob, \ args=(bobDir,bobDomain,bobPort, \ @@ -1286,6 +1343,14 @@ def testClientToServer(): aliceDomain='127.0.0.42' alicePort=61935 aliceSendThreads=[] + + global thrAlice + if thrAlice: + while thrAlice.isAlive(): + thrAlice.stop() + time.sleep(1) + thrAlice.kill() + thrAlice = \ threadWithTrace(target=createServerAlice, \ args=(aliceDir,aliceDomain,alicePort, \ @@ -1296,6 +1361,14 @@ def testClientToServer(): bobDomain='127.0.0.64' bobPort=61936 bobSendThreads=[] + + global thrBob + if thrBob: + while thrBob.isAlive(): + thrBob.stop() + time.sleep(1) + thrBob.kill() + thrBob = \ threadWithTrace(target=createServerBob, \ args=(bobDir,bobDomain,bobPort, \ diff --git a/threads.py b/threads.py index a5b940081..55c2a0945 100644 --- a/threads.py +++ b/threads.py @@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import threading +import os import sys import trace import time @@ -134,5 +135,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None: if debug: sendLogFilename=baseDir+'/send.csv' - with open(sendLogFilename, "a+") as logFile: - logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ")+','+str(noOfActiveThreads)+','+str(len(threadsList))+'\n') + try: + with open(sendLogFilename, "a+") as logFile: + logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ")+','+str(noOfActiveThreads)+','+str(len(threadsList))+'\n') + except: + pass