mirror of https://gitlab.com/bashrc2/epicyon
Removing dormant threads
parent
6ea855feef
commit
49d252c0d1
5
posts.py
5
posts.py
|
@ -20,6 +20,7 @@ import time
|
||||||
from time import gmtime, strftime
|
from time import gmtime, strftime
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from threads import threadWithTrace
|
from threads import threadWithTrace
|
||||||
|
from threads import removeDormantThreads
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from cache import expirePersonCache
|
from cache import expirePersonCache
|
||||||
|
@ -1128,8 +1129,10 @@ def sendPost(projectVersion: str, \
|
||||||
toDomain,toPort, \
|
toDomain,toPort, \
|
||||||
postPath,httpPrefix,withDigest,postJsonStr)
|
postPath,httpPrefix,withDigest,postJsonStr)
|
||||||
|
|
||||||
|
removeDormantThreads(sendThreads,debug)
|
||||||
|
|
||||||
# Keep the number of threads being used small
|
# Keep the number of threads being used small
|
||||||
while len(sendThreads)>10:
|
while len(sendThreads)>20:
|
||||||
sendThreads[0].kill()
|
sendThreads[0].kill()
|
||||||
sendThreads.pop(0)
|
sendThreads.pop(0)
|
||||||
thr = threadWithTrace(target=threadSendPost,args=(session, \
|
thr = threadWithTrace(target=threadSendPost,args=(session, \
|
||||||
|
|
26
threads.py
26
threads.py
|
@ -70,3 +70,29 @@ class threadWithTrace(threading.Thread):
|
||||||
return threadWithTrace(target=fn, \
|
return threadWithTrace(target=fn, \
|
||||||
args=self._args, \
|
args=self._args, \
|
||||||
daemon=True)
|
daemon=True)
|
||||||
|
|
||||||
|
def removeDormantThreads(threadsList: [],debug: bool) -> None:
|
||||||
|
"""Removes threads whose execution has completed
|
||||||
|
"""
|
||||||
|
if len(threadsList)==0:
|
||||||
|
return
|
||||||
|
|
||||||
|
dormantThreads=[]
|
||||||
|
|
||||||
|
# which threads are dormant?
|
||||||
|
noOfActiveThreads=0
|
||||||
|
for th in threadsList:
|
||||||
|
if not th.is_alive():
|
||||||
|
dormantThreads.append(th)
|
||||||
|
else:
|
||||||
|
noOfActiveThreads+=1
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+str(noOfActiveThreads) + ' active threads out of '+str(len(threadsList)))
|
||||||
|
|
||||||
|
# remove the dormant threads
|
||||||
|
dormantCtr=0
|
||||||
|
for th in dormantThreads:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: Removing dormant thread '+str(dormantCtr))
|
||||||
|
dormantCtr+=1
|
||||||
|
threadsList.remove(th)
|
||||||
|
|
Loading…
Reference in New Issue