The previous answer that was posted here How yield catches StopIteration exception? and accepted shows the following:
iterator = iter(iterable) try: while True: item = next(iterator) do_stuff(item) except StopIteration: pass finally: del iterator
The problem in Python 3.6.4 pass hangs indefinitely never closing out of the program cleanly.
del complains that the iterator is not defined when it is. My assumption is scope changes.
Any ideas how to exit cleanly when StopIteration is raised?