def repeatAlways(child, **kwargs): """Perpetually iterate over the child, regardless of return value. """ result = None while True: try: visitor = core.visit(child, **kwargs) except StopIteration: continue while result is None: try: result = (yield visitor.next()) except StopIteration: yield None break
def limit(child, **kwargs): """Limit the child to only iterate once every period. Otherwise, act as an identity decorator. @keyword limit_period: how often to run the child, in seconds. """ nowtime = time.time last_run = nowtime() period = kwargs.get('limit_period', 1.0) result = None visitor = core.visit(child, **kwargs) while True: now = nowtime() since_last = now - last_run if (since_last) <= period: yield None continue last_run = nowtime() result = visitor.next() yield result