Sounds like the program is done by the time control-c has been hit, but your operating system hasn't finished showing you all the output. .
Answer from Andy V on Stack OverflowSounds like the program is done by the time control-c has been hit, but your operating system hasn't finished showing you all the output. .
code flow is as follows:
forgrabs new object from list (generated byrange) and setsito ittryprint- go back to
1
If you hit CTRL-C in the part 1 it is outside the try/except, so it won't catch the exception.
Try this instead:
MaxVal = 10000
StepInterval = 10
try:
for i in range(1, MaxVal, StepInterval):
print i
except KeyboardInterrupt:
pass
print "done"
The assignment is to create a zigzag wiggle pattern using stars, in an infinite loop, which should end in case the user clicks any button. I don't know if it's a mistake on my end or some functionality on the Mu Editor, but nothing really happens when I press any key while the code is running. Is it a fault with my code? How do I fix this?
KeyboardInterrupt and SystemExit in exception groups should be considered for Python's exit code - Ideas - Discussions on Python.org
KeyboardInterrupt ignored on Windows
python - KeyboardInterrupt not raised or caught in the case of broad Exception - Stack Overflow
How can I add an keyboard interrupt to a program?
Videos
On Windows, in the interactive Python interpreter, the options to exit are:
quit()exit()Ctrl + Z then Enter
Ctrl + Break
When running scripts, Ctrl + C can generally be used to send a KeyboardInterrupt that halts script execution (note that a Traceback will be generated).
The Ctrl + Break option assumes your keyboard has a Break or Pause/Break key.
On Linux, you can use
- the commands
quit()orexit() - or the key combination Ctrl+D
Pressing Ctrl+C in the Python Interpreter only causes a KeyboardInterrupt exception.
Pressing Ctrl+Break in Linux does nothing relevant in regard to the Python shell.
Pressing Ctrl+Z merely stops and puts the Python process to the background without ending it.