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 # 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, self._args = ScratchPad(name=name, log=log, verbose=verbose, fullReport=fullReport,
findCycles=findCycles, doneCallback=doneCallback) findCycles=findCycles, doneCallback=doneCallback)
self._printing = False
jobMgr.add(self) jobMgr.add(self)
if threaded == False: if threaded == False:
jobMgr.finish(self) jobMgr.finish(self)
@ -46,10 +45,14 @@ class GarbageReport(Job):
gc.set_debug(gc.DEBUG_SAVEALL) gc.set_debug(gc.DEBUG_SAVEALL)
gc.collect() gc.collect()
yield None yield None
self.notify.debug('gc.garbage == %s' % fastRepr(gc.garbage)) # don't repr the garbage list if we don't have to
yield None if self.notify.getDebug():
self.notify.debug('gc.garbage == %s' % fastRepr(gc.garbage))
yield None
self.garbage = list(gc.garbage) 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[:] del gc.garbage[:]
if not wasOn: if not wasOn:
gc.set_debug(oldFlags) gc.set_debug(oldFlags)
@ -175,22 +178,15 @@ class GarbageReport(Job):
self._report = s self._report = s
if self._args.log: if self._args.log:
self._printing = True self.printingBegin()
for i in xrange(len(self._report)): for i in xrange(len(self._report)):
print self._report[i] print self._report[i]
if (not (i & 0x3F)): if (not (i & 0x3F)):
yield None yield None
self._printing = False self.printingEnd()
yield Job.Done 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): def finished(self):
if self._args.doneCallback: if self._args.doneCallback:
self._args.doneCallback(self) self._args.doneCallback(self)

View File

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