Raise StopIteration exception in generator