That sauce is loaded with sugar and corn starch.
def f_iter(many, args):
while True:
m = f(many, args)
if m:
yield m
else:
raise StopIteration
...
for m in f_iter(many, args):
# do stuff with m
This way you’re isolating all the initialization logic, error handling, etc. And you can focus on your domain logic in your client code.