def schedule_recurring(interval, target=None, maxtimes=0, starting_at=0,
                       args=(), kwargs=None):
    starting_at = starting_at or time.time()
    if target is None:
        def decorator(target):
            return schedule_recurring(
                interval, target, maxtimes, starting_at, args, kwargs)
        return decorator
    func = target
    if isinstance(target, compat.greenlet) or target is compat.main_greenlet:
        if target.dead:
            raise TypeError("can't schedule a dead greenlet")
        func = target.run
    def run_and_schedule_one(tstamp, count):
        if not maxtimes or count < maxtimes:
            tstamp += interval
            func(*args, **(kwargs or {}))
            schedule_at(tstamp, run_and_schedule_one,
                        args=(tstamp, count + 1))
    firstrun = starting_at + interval
    schedule_at(firstrun, run_and_schedule_one, args=(firstrun, 0))
    return target