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"
|
||||
|
||||
import threading
|
||||
import os
|
||||
import sys
|
||||
import trace
|
||||
import time
|
||||
import datetime
|
||||
|
||||
|
||||
class threadWithTrace(threading.Thread):
|
||||
def __init__(self, *args, **keywords):
|
||||
self.startTime = datetime.datetime.utcnow()
|
||||
|
@ -65,10 +64,11 @@ class threadWithTrace(threading.Thread):
|
|||
self.killed = True
|
||||
|
||||
def clone(self, fn):
|
||||
return threadWithTrace(target=fn, \
|
||||
args=self._args, \
|
||||
return threadWithTrace(target=fn,
|
||||
args=self._args,
|
||||
daemon=True)
|
||||
|
||||
|
||||
def removeDormantThreads(baseDir: str, threadsList: [], debug: bool) -> None:
|
||||
"""Removes threads whose execution has completed
|
||||
"""
|
||||
|
@ -88,7 +88,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None:
|
|||
if not th.is_alive():
|
||||
if (currTime - th.startTime).total_seconds() > 10:
|
||||
if debug:
|
||||
print('DEBUG: thread is not alive ten seconds after start')
|
||||
print('DEBUG: ' +
|
||||
'thread is not alive ten seconds after start')
|
||||
removeThread = True
|
||||
# timeout for started threads
|
||||
if (currTime - th.startTime).total_seconds() > 600:
|
||||
|
@ -107,7 +108,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None:
|
|||
else:
|
||||
noOfActiveThreads += 1
|
||||
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
|
||||
dormantCtr = 0
|
||||
|
@ -137,6 +139,8 @@ def removeDormantThreads(baseDir: str,threadsList: [],debug: bool) -> None:
|
|||
sendLogFilename = baseDir + '/send.csv'
|
||||
try:
|
||||
with open(sendLogFilename, "a+") as logFile:
|
||||
logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ")+','+str(noOfActiveThreads)+','+str(len(threadsList))+'\n')
|
||||
except:
|
||||
logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ") +
|
||||
',' + str(noOfActiveThreads) +
|
||||
',' + str(len(threadsList)) + '\n')
|
||||
except BaseException:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue