mirror of https://gitlab.com/bashrc2/epicyon
flake8 format
parent
02ce4e3d14
commit
ad2c26eebf
20
threads.py
20
threads.py
|
@ -7,12 +7,11 @@ __email__="bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import trace
|
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
class threadWithTrace(threading.Thread):
|
class threadWithTrace(threading.Thread):
|
||||||
def __init__(self, *args, **keywords):
|
def __init__(self, *args, **keywords):
|
||||||
self.startTime = datetime.datetime.utcnow()
|
self.startTime = datetime.datetime.utcnow()
|
||||||
|
@ -65,10 +64,11 @@ class threadWithTrace(threading.Thread):
|
||||||
self.killed = True
|
self.killed = True
|
||||||
|
|
||||||
def clone(self, fn):
|
def clone(self, fn):
|
||||||
return threadWithTrace(target=fn, \
|
return threadWithTrace(target=fn,
|
||||||
args=self._args, \
|
args=self._args,
|
||||||
daemon=True)
|
daemon=True)
|
||||||
|
|
||||||
|
|
||||||
def removeDormantThreads(baseDir: str, threadsList: [], debug: bool) -> None:
|
def removeDormantThreads(baseDir: str, threadsList: [], debug: bool) -> None:
|
||||||
"""Removes threads whose execution has completed
|
"""Removes threads whose execution has completed
|
||||||
"""
|
"""
|
||||||
|
@ -88,7 +88,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None:
|
||||||
if not th.is_alive():
|
if not th.is_alive():
|
||||||
if (currTime - th.startTime).total_seconds() > 10:
|
if (currTime - th.startTime).total_seconds() > 10:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: thread is not alive ten seconds after start')
|
print('DEBUG: ' +
|
||||||
|
'thread is not alive ten seconds after start')
|
||||||
removeThread = True
|
removeThread = True
|
||||||
# timeout for started threads
|
# timeout for started threads
|
||||||
if (currTime - th.startTime).total_seconds() > 600:
|
if (currTime - th.startTime).total_seconds() > 600:
|
||||||
|
@ -107,7 +108,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None:
|
||||||
else:
|
else:
|
||||||
noOfActiveThreads += 1
|
noOfActiveThreads += 1
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: '+str(noOfActiveThreads) + ' active threads out of '+str(len(threadsList)))
|
print('DEBUG: ' + str(noOfActiveThreads) +
|
||||||
|
' active threads out of ' + str(len(threadsList)))
|
||||||
|
|
||||||
# remove the dormant threads
|
# remove the dormant threads
|
||||||
dormantCtr = 0
|
dormantCtr = 0
|
||||||
|
@ -137,6 +139,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None:
|
||||||
sendLogFilename = baseDir + '/send.csv'
|
sendLogFilename = baseDir + '/send.csv'
|
||||||
try:
|
try:
|
||||||
with open(sendLogFilename, "a+") as logFile:
|
with open(sendLogFilename, "a+") as logFile:
|
||||||
logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ")+','+str(noOfActiveThreads)+','+str(len(threadsList))+'\n')
|
logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ") +
|
||||||
except:
|
',' + str(noOfActiveThreads) +
|
||||||
|
',' + str(len(threadsList)) + '\n')
|
||||||
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue