Using the curses module on Windows (via this PDCurses), I am trying to break on a KeyboardInterrupt exception, but it doesn't raise when I press ctrl+c.
Some distilled code:
from curses import wrapper
items = ['a', 'very', 'long', 'list', 'of', 'strings']
def main(screen):
for item in items:
screen.addstr(0, 0, item)
screen.getch()
screen.refresh()
wrapper(main)
The items list is very long, and right now I can't stop execution half-way. I have to just press keys repeatedly until I get to the end. Heaven forbid I ever try this in a while True:!
When I press ctrl+c, no exception is raised. It does pass to my getch() as 3. Is SOP to raise manually when getch receives 3, or is there a more proper way to avoid swallowing KeyboardInterrupt?
By default
cursesuserawmode, which turns off interrupt/quit/suspend etc. from the documentationFrom the C's curses documentation:
Since python raises a
KeyboardInterruptwhen aSIGINTis sent, the fact that it isn't raised is expected. The3that you see does represent an interrupt.Since this is something handled by the C library there is no way to avoid this "swallowing" of the exception. You can however use a simple wrapper for
getchthat checks when it returns3and raises an error accordingly.