def first_evlp(): try: yield sleep(1) yield req() yield launch(second) finally: eventloop.halt()
def req(): client = HttpClient() try: resp = yield client.request('http://www.google.com/') print resp.code, resp.body finally: eventloop.halt()
def _run_async(ctx): try: yield fn() except Exception: traceback.print_exc(file=sys.stdout) ctx['exit_code'] = 1 finally: eventloop.halt()
def do_echos(): try: client = Client() yield client.connect('localhost', 8000) t = time.time() for x in xrange(10000): msg = "hello, world #%s!" % x yield client.write(msg + '\r\n') echo_result = yield client.read_until("\r\n") assert echo_result.strip() == "you said: %s" % msg print '10000 loops in %.2fs' % (time.time() - t) finally: eventloop.halt()
def do_echos(): try: client = Client() yield client.connect('localhost', 8000) t = time.time() for x in xrange(10000): msg = "hello, world #%s!" % x yield client.write(msg + '\r\n') echo_result = yield client.read_until("\r\n") assert echo_result.strip() == "you said: %s" % msg print '10000 loops in %.2fs' % (time.time() - t) finally: client.close() eventloop.halt()
def req(): client = HttpClient() try: yield client.connect("www.google.com", 80) resp = yield client.request('/') print resp.code, repr(resp.body) resp = yield client.request('http://www.google.com/') print resp.code, repr(resp.body) client.close() yield client.connect("localhost", 80) resp = yield client.request('/') print resp.code, repr(resp.body) resp = yield client.request('http://localhost/') print resp.code, repr(resp.body) finally: eventloop.halt()
def run(tests, verbose=False): global _fail_count try: #print tests results = [] start_time = time.time() for test in tests: result = yield test(verbose) results.append(result) duration = time.time() - start_time print print "----------------------------------------------------------------------" print "Ran %s tests in %.3fs" % (len(tests), duration) print _fail_count = 0 for result in results: if result['type'] != "SUCCESS": _fail_count += 1 test = result['test'] print "======================================================================" print "%s %s (%s)" % (result['type'], test.__doc__ or test.__name__, __file__) print "----------------------------------------------------------------------" print result['tb'] if result['stdout']: print "-------------------- >> begin captured stdout << ---------------------" print result['stdout'] print "--------------------- >> end captured stdout << ----------------------" if result['stderr']: print "-------------------- >> begin captured stderr << ---------------------" print result['stderr'] print "--------------------- >> end captured stderr << ----------------------" if result['log']: print "-------------------- >> begin captured log << ---------------------" print result['log'] print "--------------------- >> end captured log << ----------------------" if not _fail_count: print "OK" finally: from monocle.stack import eventloop eventloop.halt()
def send(dir, coin, to): try: receipt=Send(None, pub, epoch(), coin, loadPublic(to)) receipt.setPrivate(priv) receipt.sign() receipts=Receipts() receipts.load(dir+'/receipts.dat') receipts.add(receipt) smsg=json.dumps(receipt.save(True)) print('sending') client=Client() yield client.connect('localhost', 7050) yield client.write(smsg+"\n") s=yield client.read_until("\n") msg=json.loads(s) receipt=Receive() receipt.load(msg) if receipt.cmd!='receive': print('Unknown command: '+str(receipt.cmd)) return if receipt.args.save_pkcs1('DER')!=pub.save_pkcs1('DER'): print('Not me') return if not rsa.verify(str(receipt.sig), receipt.pub): print('Not verified') return cs.save(dir+'/coins.dat') receipts.add(receipt) print('saving '+str(len(receipts.receipts))) receipts.save(dir+'/receipts.dat') eventloop.halt() except Exception, e: print('Exception:') print(e) traceback.print_exc()
def main(): c = Client() """ yield c.connect('google.com', 80) yield c.write("GET / HTTP/1.0\r\n\r\n") x = None c.timeout = 0 try: x = yield c.read(40000) except Exception, e: print str(e) print x """ c.timeout = 1 yield c.connect('google.com', 80) yield c.write("GET / HTTP/1.0\r\n\r\n") c.timeout = 0 x = yield c.read(40000) print(x) eventloop.halt()
def wrapper(chan): r = yield target(*args, **kwargs) yield chan.send(r) eventloop.halt()
def print_every_two_seconds(): for i in xrange(5): print "2" yield sleep(2) eventloop.halt()