<s> import time <EOL> import ufora . util . StackInfo as StackInfo <EOL> import threading <EOL> def writeStackTraceSummary ( stackLog ) : <EOL> '''<STR_LIT>''' <EOL> traceDict = { } <EOL> for id , traceList in StackInfo . getTraces ( ) . iteritems ( ) : <EOL> trace = '<STR_LIT>' . join ( traceList ) <EOL> if trace not in traceDict : <EOL> traceDict [ trace ] = [ ] <EOL> traceDict [ trace ] . append ( id ) <EOL> for trace , idList in traceDict . iteritems ( ) : <EOL> for id in idList : <EOL> stackLog . write ( str ( id ) + '<STR_LIT:\n>' ) <EOL> stackLog . write ( "<STR_LIT>" . join ( trace ) ) <EOL> stackLog . write ( '<STR_LIT>' ) <EOL> def stacktraceWriteLoop ( logfileLocation , timeout = <NUM_LIT:20> ) : <EOL> while True : <EOL> time . sleep ( timeout ) <EOL> with open ( logfileLocation , '<STR_LIT:w>' ) as stackLog : <EOL> writeStackTraceSummary ( stackLog ) <EOL> def startLoop ( logfileLocation , timeout = <NUM_LIT:20> ) : <EOL> t = threading . Thread ( target = stacktraceWriteLoop , args = ( logfileLocation , timeout ) ) <EOL> t . daemon = True <EOL> t . start ( ) </s>
