KeyBoardInterrupt error
Michael Hudson
mwh21 at cam.ac.uk
Thu Mar 29 17:22:05 EST 2001
Headers indicate evolution, so Linux, right?
Jason "Straw." <jstraw at towhee.com> writes:
> What can trigger a Keyboard Interrupt?
Receiving a SIGINT. The terminal driver will send one of those if you
hit Ctrl-C (by default).
> I need Ctrl-C to be ignored and Ctrl-D to map to a function.
Two options for ignoring Ctrl-C: use termios to tuen off the ISIG
flag, along the lines of
import termios
import TERMIOS
n = termios.tcgetattr(0)
n[3] &=~ TERMIOS.ISIG
termios.tcsetattr(0, TERMIOS.TCSANOW, n)
but with some kind of error checking & stuff or use signal to ignore
SIGINTs:
signal.signal(signal.SIGINT,signal.SIG_IGN)
Note that when you're playing around at the console that readline
tends to reset both of these, which is nice, and that both of these
will leave ^C in the input stream (it seems).
Ctrl-D just causes reads to abort early. If you're using raw_input()
(a) don't, if you want this level of control (b) just catch EOFErrors
and restart your loop.
> gettting a single char at a time is a bad idea for my project
Eh? How does this relate to the above?
If you're interested in line input, you *might* want to look at my
python line reader, which was tentatively dubbed "pyrl", but needs a
new name ("pyrl" is taken). It's not really finished; find it at:
http://www-jcsu.jesus.cam.ac.uk/~mwh21/hacks/pyrl-0.2.0.tar.gz
To test drive, unpack & go:
$ python python_reader.py
(requires Python 2).
I've almost got incremental history searching done on my hard drive,
but a few bugs and some additional commitments have stalled me...
Anybody interested in seeing more, or have a better name than
pyttyinput?
Cheers,
M.
--
I'll write on my monitor fifty times 'I must not post self-indulgent
wibble nobody is interested in to ucam.chat just because I'm bored
and I can't find the bug I'm supposed to fix'.
-- Steve Kitson, ucam.chat
More information about the Python-list
mailing list