New submission from Bernie H. Innocenti <ber...@codewiz.org>: On startup, the Python interpreter changes the default behavior of SIGINT, which results in many Python programs to ignore the keyboard interrupt exactly in the situations when users are most likely to use it (i.e.: when the program becomes unresponsive).
Minimal testcase: $ echo "void foo() { for(;;) {} }" >foo.c $ gcc -shared -o foo.so foo.c $ python -c 'import ctypes;ctypes.CDLL("./foo.so").foo()' ^C^C^C ^C ^C DAMN! ^C This scenario mimics a Python program calling some blocking library function. It can also happen with IO-bound functions if they loop on read() and don't abort on short reads. One might be tempted to say "this behavior of the Python intepreter is by design" and suggest users to use CTRL-\ instead of CTRL-C. However, this non-standard behavior is very annoying for users who expect ^C to work on UNIX systems. In fact, no other compiled or interpreted language I know of behaves this way, and Python should not be the only exception. While I see the usefulness of KeyboardInterrupt from the programmer point of view, only a minority of programs actually need to trap SIGINT and do something with it. Other language runtimes require the programmer to manually trap SIGINT when needed. The Python interpreter could maintain backwards compatibility by enabling automatic SIGINT trapping when entering a "try" block that would intercept KeyboardInterrupt. ---------- components: Interpreter Core messages: 92576 nosy: bernie severity: normal status: open title: Runaway programs often become unresponsive to CTRL-C versions: Python 2.6, Python 3.0 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6901> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com