class QuasiAsynchronousDownloader(Downloader): def preloop(self): self.downloads = [] mi = multi_iter(self.downloads, terminate=False) self.lc = ThreadedLoopingCall(mi.next) self.lc.start() def postloop(self): self.lc.stop() Downloader.postloop(self) def do_download(self, arg): self.downloads.append(self.download(arg)) def download(self, fname): self.out.write("BEGIN %s" % fname) for line in file(fname): time.sleep(.1) self.out.write(".") yield None self.out.write(" END %s\n" % fname)
def preloop(self): self.downloads = [] mi = multi_iter(self.downloads, terminate=False) self.lc = ThreadedLoopingCall(mi.next) self.lc.start()