Resume an Iterator
Question: Is there a way to resume an iterator after a keyboard interrupt signal or
other SIGINT signal in python?

Specifically for itertools iterator

`import itertools for word in itertools.product("abcd",repeat=3): print(word)`

I want to resume printing from where it left off


Answer: You can catch keyboard interrupts in a try/except block

    
    
    import itertools
    import time
    for word in itertools.product("abcd",repeat=3):
      try:
        print(word)
        time.sleep(1)
      except:
        pass  
    

Hitting Ctrl+C during executing does not stop the iteration

