def multigen(gen_func):


    class _multigen(object):

        def __init__(self, *args, **kwargs):
            self.__args = args
self.__kwargs = kwargs

def __iter__(self):
    return gen_func(*self.__args, **self.__kwargs)
return _multigen

@multigen
def myxrange(n):
    i = 0
while i < n:
    yield i
i += 1
m = myxrange(5)
print(list(m))
print(list(m))
How to make a repeating generator in Python