Message106799
Run test.py (below) in terminal, and interrupt it with Ctrl-C.
Result: terminal settings are not restored (checked with linux console and xterm, with Python 2.7 and 3.2).
# test.py
# Broke it with KeyboardInterrupt
import curses
def main(screen):
k = screen.getkey()
curses.wrapper(main)
# Results are hardly readable due to the broken terminal.
# Something about KeyboardInterrupt
However, if getkey() is surrounded by try-except, behavior changes:
# test2.py
# Broke it with KeyboardInterrupt
import curses
def main2(screen):
try:
k = screen.getkey()
except KeyboardInterrupt:
raise
curses.wrapper(main2)
# Terminal is restored to its normal state.
In python3.2 test2.py results in traceback:
Traceback (most recent call last):
File "test2.py", line 4, in main2
k = screen.getkey()
_curses.error: no input
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test2.py", line 7, in <module>
curses.wrapper(main2)
File "/usr/local/lib/python3.2/curses/wrapper.py", line 44, in wrapper
return func(stdscr, *args, **kwds)
File "test2.py", line 4, in main2
k = screen.getkey()
KeyboardInterrupt
In 2.7 it results only in the latest part of traceback:
Traceback (most recent call last):
File "test2.py", line 7, in <module>
curses.wrapper(main2)
File "/usr/local/lib/python2.7/curses/wrapper.py", line 44, in wrapper
return func(stdscr, *args, **kwds)
File "test2.py", line 4, in main2
k = screen.getkey()
KeyboardInterrupt
The problem is that instead of a single KeyboardInterrupt, two exceptions are raised: KeyboardInterrupt and _curses.error('no input').
Possible solution is to suppress _curses.error in this case (since it is less relevant than KeyboardInterrupt, IMO). |
|
Date |
User |
Action |
Args |
2010-05-31 18:23:59 | july | set | recipients:
+ july |
2010-05-31 18:23:59 | july | set | messageid: <1275330239.59.0.0964939469403.issue8862@psf.upfronthosting.co.za> |
2010-05-31 18:23:57 | july | link | issue8862 messages |
2010-05-31 18:23:56 | july | create | |
|