# Run this file through "spin" to get a .py file. import Yarn from Yarn import simtime import random def trylickin(thing): print "%f: I'm gonna try lickin' %s"%(simtime(), thing) for i in range(1,21): r = random.uniform(1, 2) waitfor Yarn.sleep(r) print "%f: Lick %d of %s took %f seconds..."%(simtime(),i,thing,r) if random.uniform(0, 10) < 1: print "%f: But that was enough, I'm satisfied!"%(simtime()) exit i if random.uniform(0, 10) < 1: print "%f: But... gasp... poison!"%(simtime()) raise Exception, thing def reportLicks(thing): try: tries = waitfor trylickin(thing) except Exception, e: print "%f: Lickin' tester of %s DIED! (exception=%s)"%(simtime(), thing, e) print "%f: Starting over..."%(simtime()) spawn reportLicks(thing) else: if tries: print "%f: Lickin' tester reports back %d tries for %s"%(simtime(), tries, thing) else: print "%f: Lickin' tester didn't report # of tries for %s!"%(simtime(), thing) spawn reportLicks("Tootsie Roll Pop") spawn reportLicks("Rover") at 5. Yarn.run()