added printingBegin/printingEnd to standardize suspend/resume logging

This commit is contained in:
Darren Ranalli 2007-03-14 08:34:01 +00:00
parent 78b10c41ba
commit 6229b8bdcc
2 changed files with 25 additions and 17 deletions

View File

@ -33,7 +33,6 @@ class GarbageReport(Job):
# stick the arguments onto a ScratchPad so we can delete them all at once
self._args = ScratchPad(name=name, log=log, verbose=verbose, fullReport=fullReport,
findCycles=findCycles, doneCallback=doneCallback)
self._printing = False
jobMgr.add(self)
if threaded == False:
jobMgr.finish(self)
@ -46,10 +45,14 @@ class GarbageReport(Job):
gc.set_debug(gc.DEBUG_SAVEALL)
gc.collect()
yield None
self.notify.debug('gc.garbage == %s' % fastRepr(gc.garbage))
yield None
# don't repr the garbage list if we don't have to
if self.notify.getDebug():
self.notify.debug('gc.garbage == %s' % fastRepr(gc.garbage))
yield None
self.garbage = list(gc.garbage)
self.notify.debug('self.garbage == %s' % self.garbage)
# don't repr the garbage list if we don't have to
if self.notify.getDebug():
self.notify.debug('self.garbage == %s' % self.garbage)
del gc.garbage[:]
if not wasOn:
gc.set_debug(oldFlags)
@ -175,22 +178,15 @@ class GarbageReport(Job):
self._report = s
if self._args.log:
self._printing = True
self.printingBegin()
for i in xrange(len(self._report)):
print self._report[i]
if (not (i & 0x3F)):
yield None
self._printing = False
self.printingEnd()
yield Job.Done
def suspend(self):
if self._printing:
self.notify.info('SUSPEND')
def resume(self):
if self._printing:
self.notify.info('RESUME')
def finished(self):
if self._args.doneCallback:
self._args.doneCallback(self)

View File

@ -14,28 +14,40 @@ class Job:
self._name = name
self._generator = None
self._id = Job._SerialGen.next()
self._printing = False
def destroy(self):
del self._name
del self._generator
del self._printing
def run(self):
# this is a generator
# override and do your processing
# yield Job.Continue when possible/reasonable
# try not to run longer than the JobManager's timeslice between yields
#
# when done, yield Job.Done
#
raise "don't call down"
def getPriority(self):
# override if you want a different priority
return Job.Priorities.Normal
def printingBegin(self):
self._printing = True
def printingEnd(self):
self._printing = False
def resume(self):
# called every time JobManager is going to start running this job
if self._printing:
print 'JOB:%s:RESUME' % self._name
def suspend(self):
# called when JobManager is going to stop running this job for a while
pass
def resume(self):
# called when JobManager is going to start running this job again
pass
if self._printing:
print 'JOB:%s:SUSPEND' % self._name
def finished(self):
# called when the job finishes and has been removed from the JobManager