In the following program
import itertools
for i in itertools.count():
print (i)
I wanted to stop this event using keyboard press events.
In the following program
import itertools
for i in itertools.count():
print (i)
I wanted to stop this event using keyboard press events.
You can wait for a KeyboardInterrupt
exception and then get out:
import itertools
try:
# Stay inside the loop until Ctrl+C is pressed
for i in itertools.count():
print (i)
except KeyboardInterrupt:
pass
# Go on...