def gen(): global a for i in xrange(m): df = Deferred() #rawserver.add_task(0, df.callback, lambda r: r) df.callback(1) like_yield_stackless(df) a[i] = time.clock()
def launch_coroutine(queue_task, f, *args, **kwargs): main_df = Deferred() try: g = f(*args, **kwargs) except Exception, e: if debug: traceback.print_exc() main_df.errback(Failure())
def gen(): global a for i in xrange(m): df = Deferred() #rawserver.add_task(0, df.callback, lambda r: r) df.callback(1) yield df df.getResult() a[i] = time.clock()
def initiateOp(self, handle, seekpos, buffer): df = Deferred() try: self.reactor.issueReadFile(handle, seekpos, buffer, self.ovDone, (handle, buffer)) except: df.errback(Failure()) else: self.df = df return df
def initiateOp(self, handle, seekpos, buffer): assert len(buffer) > 0 assert seekpos >= 0 df = Deferred() try: self.op(handle, seekpos, buffer, self.ovDone, (handle, buffer)) except: df.errback(Failure()) else: self.df = df return df
def acquire_handle(self, filename, for_write, length=0): df = Deferred() # abort disk ops on unregistered files if filename not in self.file_to_torrent: df.callback(None) return df if self.active_file_to_handles.total_length() == self.max_files_open: self.waiting_ops.append((df, filename, for_write, length)) else: self._produce_handle(df, filename, for_write, length) return df
def getOwie(): d = Deferred() def CRAP(): d.errback(ZeroDivisionError('OMG')) reactor.callLater(0, CRAP) return d
def test_rate_limited_logger(): injectLogger(verbose = True) log = RateLimitedLogger(logging.getLogger("myapp"), 1,1) log.info( "should be printed." ) log.info( "should not be printed" ) # but should log "discard" message. log.info( "also should not be printed" ) # should not logging of discard message. df = Deferred() reactor.callLater(3, df.callback, True) like_yield(df) log.info( "should also be printed" ) reactor.stop()
def acquire_handle(self, filename, for_write, length=0): df = Deferred() if filename not in self.file_to_torrent: raise UnregisteredFileException() if self.active_file_to_handles.total_length() == self.max_files_open: self.waiting_ops.append((df, filename, for_write, length)) else: self._produce_handle(df, filename, for_write, length) return df
def create_torrent(self, metainfo, save_incomplete_as, save_as, hidden=False, is_auto_update=False, feedback=None): if self.is_single_torrent and len(self.torrents) > 0: raise TooManyTorrents(_("MultiTorrent is set to download only " "a single torrent, but tried to create more than one.")) infohash = metainfo.infohash if self.torrent_known(infohash): if self.torrent_running(infohash): msg = _("This torrent (or one with the same contents) is " "already running.") raise TorrentAlreadyRunning(msg) else: raise TorrentAlreadyInQueue(_("This torrent (or one with " "the same contents) is " "already waiting to run.")) self._dump_metainfo(metainfo) #BUG. Use _read_torrent_config for 5.0? --Dave config = configfile.read_torrent_config(self.config, self.data_dir, infohash, lambda s : self.global_error(logging.ERROR, s)) t = Torrent(metainfo, save_incomplete_as, save_as, self.config, self.data_dir, self.rawserver, self.choker, self.singleport_listener, self.up_ratelimiter, self.down_ratelimiter, self.total_downmeasure, self.filepool, self.dht, self, self.log_root, hidden=hidden, is_auto_update=is_auto_update) if feedback: t.add_feedback(feedback) retdf = Deferred() def torrent_started(*args): if config: t.update_config(config) t._dump_torrent_config() if self.resume_from_torrent_config: self._dump_torrents() t.metainfo.show_encoding_errors(self.logger.log) retdf.callback(t) df = self._init_torrent(t, use_policy=False) df.addCallback(torrent_started) return retdf
def getThing(): d = Deferred() reactor.callLater(0, d.callback, "hi") return d
def close_files(self, file_set): df = Deferred() self._close_files(df, file_set) return df
def close_all(self): df = Deferred() self._close_all(df) return df
def _create_op(self, _f, *args, **kwargs): df = Deferred() self.diskq.put((df, _f, args, kwargs)) return df
def task(name, error=False): df = Deferred() df.error = error queue.put(df) return df
def wait(n): df = Deferred() reactor.callLater(n, df.callback, 0) return df