def stop(self): """ Perform any cleanup and remove ourself from the pool before exiting """ moveBackSamples(self) if not self.forcedRecovery: cleanUp(self.dirName) if not self.isSubDir: Hellanzb.postProcessorLock.acquire() Hellanzb.postProcessors.remove(self) self.archive.postProcessor = None Hellanzb.postProcessorLock.release() # Write the queue to disk unless we've been stopped by a killed Topen (via # CTRL-C) if not self.killed and not self.isSubDir and self.background: Hellanzb.writeStateXML() # When a Post Processor fails, we end up moving the destDir here self.moveDestDir() # FIXME: This isn't the best place to GC. The best place would be when a download # is finished (idle NZBLeecher) but with smartpar, finding an idle NZBLeecher is # tricky if not self.isSubDir and self.isNZBArchive(): self.archive.finalize(self.forcedRecovery) if not self.forcedRecovery: del self.archive gc.collect() if self.forcedRecovery: self.callback() return if not self.background and not self.isSubDir: # We're not running in the background of a downloader -- we're post processing # and then immeidately exiting (-Lp) from twisted.internet import reactor reactor.callFromThread(reactor.stop)
def run(self): """ do the work """ if not self.isSubDir: Hellanzb.postProcessorLock.acquire() # FIXME: could block if there are too many processors going Hellanzb.postProcessors.append(self) Hellanzb.postProcessorLock.release() if not self.isSubDir and self.background: Hellanzb.writeStateXML() try: self.postProcess() except SystemExit, se: # REACTOR STOPPED IF NOT BACKGROUND/SUBIDR self.stop() if self.isSubDir: # Propagate up to the original Post Processor raise return