class Giftreceiver(object): def __init__(self): self.donaterunpromise = Promise() self.obj = None @expose def donate(self, url): #print obj, obj.conn, obj.functions print url self.obj = n.establish(url) r = self.obj.call('add', 10, 31) r._when(self.done) return self.donaterunpromise def done(self, r): print 'done using the object, result:', r self.donaterunpromise._resolve('Thanks, i am done!.') later(3, self.retry) def works(self, r): print 'reusing worked, result:', r later(3, self.retry) def err(self, e): print 'reusing error, e:', e def retry(self): if self.obj: r = self.obj.call('add', 40, 31) r._when(self.works) r._except(self.err)
def call(self, *args, **kwargs): try: return self.rc.call(REF, *args, **kwargs) except EVException: p = Promise() p._smash(EVException('Server currently unavailable.')) return p
class Cookie(object): def __init__(self, p): self.p = p self.stdout = '' self.stderr = '' self.closereason = None self.retcode = None self.promise = Promise() p._on('read', self.stdout) p._on('readerr', self.stderr) p._on('closed', self.close) def resolve(self): self.promise._resolve([self.retcode, self.closereason, self.stdout, self.stderr]) def stdout(self, data): print 'stdout', data self.stdout += data def stderr(self, data): print 'stderr', data self.stderr += data def closed(self, e): print 'closed', e self.closereason = e self.retcode = self.p.p.returncode self.resolve()
class Giftreceiver(object): def __init__(self): self.donaterunpromise = Promise() self.obj = None @expose def donate(self, url): # print obj, obj.conn, obj.functions print url self.obj = n.establish(url) r = self.obj.call("add", 10, 31) r._when(self.done) return self.donaterunpromise def done(self, r): print "done using the object, result:", r self.donaterunpromise._resolve("Thanks, i am done!.") later(3, self.retry) def works(self, r): print "reusing worked, result:", r later(3, self.retry) def err(self, e): print "reusing error, e:", e def retry(self): if self.obj: r = self.obj.call("add", 40, 31) r._when(self.works) r._except(self.err)
class Processround(object): def __init__(self, slaves, data, funcname, combinefunc): self.slaves = slaves self.data = data self.funcname = funcname self.combinefunc = combinefunc self.p = Promise() self.results = [] def run(self): amount = len(self.data) / len(self.slaves) for i in range(len(self.slaves)): rp = self.slaves[i].call( self.funcname, self.data[i * amount:(i * amount) + amount]) rp._when(self.resultcb) rp._except(self.exceptcb) return self.p def exceptcb(self, e): self.p._smash(e) def resultcb(self, result): self.results.append(result) if len(self.results) == len(self.slaves): self.p._resolve(self.combinefunc(self.results))
def __init__(self, slaves, data, funcname, combinefunc): self.slaves = slaves self.data = data self.funcname = funcname self.combinefunc = combinefunc self.p = Promise() self.results = []
class Cookie(object): def __init__(self, p): self.p = p self.stdout = '' self.stderr = '' self.closereason = None self.retcode = None self.promise = Promise() p._on('read', self.stdout) p._on('readerr', self.stderr) p._on('closed', self.close) def resolve(self): self.promise._resolve( [self.retcode, self.closereason, self.stdout, self.stderr]) def stdout(self, data): print 'stdout', data self.stdout += data def stderr(self, data): print 'stderr', data self.stderr += data def closed(self, e): print 'closed', e self.closereason = e self.retcode = self.p.p.returncode self.resolve()
def __init__(self, p): self.p = p self.stdout = '' self.stderr = '' self.closereason = None self.retcode = None self.promise = Promise() p._on('read', self.stdout) p._on('readerr', self.stderr) p._on('closed', self.close)
def __init__(self, src, dst, conn): self.src, self.dst = src, dst self.conn = conn self.done = False self.p = Promise() self.count = 0 self.burst = True conn.conn._on('writable', self.copy) conn.conn._on('close', self.closed) schedule(self.copy)
class Filestreamer(object): def __init__(self, src, dst, conn): self.src, self.dst = src, dst self.conn = conn self.done = False self.p = Promise() self.count = 0 self.burst = True conn.conn._on('writable', self.copy) conn.conn._on('close', self.closed) schedule(self.copy) def copyagain(self, r): self.burst = True schedule(self.copy) def copy(self): if self.done or self.conn.conn._closed: return if not self.burst: return self.count += 1 d = self.src.read(16384) if not d: print 'EOF on src, sending close, local close, done' p2 = self.dst.call('close') def done(r): self.p._resolve(True) self.conn.close() p2._when(done) self.done = True self.src.close() return if self.count == 10: self.burst = False self.count = 0 p = self.dst.call('write', d) p._when(self.copyagain) else: p = self.dst.notify('write', d) def closed(self, e): print 'connection closed', e if not self.done: self.p._smash('Closed, but not done, yet.')
def procfunc(self, arg): print 'procfunc called with array length', len(arg) p = Promise() def fulfill(): r = sum(arg) print 'procfunc sending result', r p._resolve(r) later(2.0, fulfill) return p
def __init__(self): self.donaterunpromise = Promise() self.obj = None