def slow_fct(): print "slow_fct" f1 = Future() def done(): print "done" f1.set_result(3) reactor.call_later(0.1, done) return f1
def update_progress(): global p r.set_progress(p) p += 5 if p < 100: reactor.call_later(0.01, update_progress) else: reactor.stop()
def test_inline_callbacks_exception1(self): reactor.reset() def print_result(result=None, error=None): assert error print "error", error[0] f = asynch_fct4() f.set_callback(print_result) reactor.call_later(1, reactor.stop) reactor.run() print "stop" assert f.completed
def test_inline_callbacks(self): reactor.reset() def print_result(result=None, error=None): print "result", result assert result == 18 f = asynch_fct2() f.set_callback(print_result) reactor.call_later(0.6, reactor.stop) reactor.run() print "stop" assert f.completed
def test_cpu_bound(self): def print_result(result=None, error=None): print "result", result assert result == 2499997500000 f1 = asynch_fct1("a") f2 = asynch_fct1("b") f1.set_callback(print_result) f2.set_callback(print_result) print "start" reactor.call_later(3, reactor.stop) reactor.run() print "stop"
def schedule_republish_transactions(self): seconds = random.randint(5 * 60, 30 * 60) reactor.call_later(seconds, self.republish_transactions)