def main(): c = boring("Joe") while True: value, chan = yield alts([c, timeout(0.8)]) if chan is c: print value else: print "You're too slow." yield stop()
def main(): c = boring("Joe") t = timeout(5) while True: value, chan = yield alts([c, t]) if chan is c: print value else: print "You talk too much." yield stop()
def main(): for url, dt in ( ("http://www.google.com/search?q=csp", 0.01), # too little time ("http://www.google.come/search?q=csp", 10), # wrong domain name ("http://www.google.com/search?q=csp", 10), ): print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" print url, dt, "seconds" c = request(url) t = timeout(dt) value, chan = yield alts([c, t]) if chan is c: result, error = value if error: print "Uhm, not good" print error else: print "Here" print result[:500] + "..." elif chan is t: print "Timeout"