[Proctor-checkins] CVS: Proctor/proctorlib cui.py, 1.20, 1.21 runner.py, 1.14, 1.15
Status: Alpha
Brought to you by:
doughellmann
|
From: Doug H. <dou...@us...> - 2006-09-15 15:10:34
|
Update of /cvsroot/proctor/Proctor/proctorlib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23113/proctorlib Modified Files: cui.py runner.py Log Message: Add --no-gc option; enable gc by default Index: cui.py =================================================================== RCS file: /cvsroot/proctor/Proctor/proctorlib/cui.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** cui.py 1 May 2006 12:47:22 -0000 1.20 --- cui.py 15 Sep 2006 15:10:29 -0000 1.21 *************** *** 55,58 **** --- 55,59 ---- # Import system modules # + import gc import string import sys *************** *** 94,97 **** --- 95,102 ---- interleaved = False category = 'All' + + def appInit(self): + gc.enable() + return def optionHandler_list(self): *************** *** 157,160 **** --- 162,171 ---- return + def optionHandler_no_gc(self): + """Disable garbage collection and leak reporting. + """ + gc.disable() + return + def showNode(self, node, data=None): num_node_tests = node.getTestSuite(0).countTestCases() Index: runner.py =================================================================== RCS file: /cvsroot/proctor/Proctor/proctorlib/runner.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** runner.py 16 Jun 2006 17:45:49 -0000 1.14 --- runner.py 15 Sep 2006 15:10:29 -0000 1.15 *************** *** 59,62 **** --- 59,63 ---- except: from StringIO import StringIO + import gc import sys import time *************** *** 74,77 **** --- 75,79 ---- # from proctorlib.trace import trace + from proctorlib import scanner # *************** *** 161,168 **** return def stopTest(self, test): trace.into('ProctorTestResult', 'stopTest', test=test) ! unittest.TestResult.stopTest(self, test) trace.outof() --- 163,231 ---- return + def _showGarbage(self): + """ + show us what's the garbage about + """ + if gc.isenabled(): + # + # Save the current settings + # + flags = gc.get_debug() + th = gc.get_threshold() + #sys.stderr.write("GC: Thresholds = %s\n" % str(th)) + + try: + # + # Perform aggressive collection + # + gc.set_debug(gc.DEBUG_LEAK) + gc.set_threshold(1, 1, 1) + # force collection + sys.stderr.write("GC: Collecting...\n") + for i in range(6): + gc.collect() + + # + # Remember what is garbage now + # + garbage = gc.garbage + finally: + gc.set_debug(flags) + gc.set_threshold(*th) + + # + # Report on current garbage + # + if not garbage: + sys.stderr.write('GC: no garbage\n') + else: + sys.stderr.write("GC: Garbage objects:\n") + for x in garbage: + for c in [ scanner.ModuleTree, + ]: + if isinstance(x, c): + # ignore + continue + + s = str(x) + #if len(s) > 80: s = s[:80] + sys.stderr.write(str(type(x))) + sys.stderr.write("\n %s\n" % s) + + # collect again without DEBUG_LEAK + gc.collect() + else: + print 'GC: disabled' + return + def stopTest(self, test): trace.into('ProctorTestResult', 'stopTest', test=test) ! unittest.TestResult.stopTest(self, test) + + try: + self._showGarbage() + except Exception, err: + print 'GC ERROR: ', err trace.outof() |