On my system ( IBM AIX 3.2 ; python sys.version '0.9.7 (DEC 20 1992)' )
the above does not seem to catch the keyboard interrupt until after
a newline. But when it does get a newline, it does do the except
[ I also just tried SunOS 4.1 python sys.version 0.9.4 and got the same
>>> def try1():
... try: sys.stdin.readline()
... except: print ' -OK.'
# ^ <return-key> hit after several control-C and "x"'s
"aaaa^Cbbbb\n" does the same.
I would have expected that it should catch the first ^C right away,
but it seems to take an interrupt in a new-line terminated string
to cause the exception.
I don't know where the problem is ( or what the expected behaviour
actually should be ) but I know stdio is prone to some odd behaviour
when used in signal catchers, etc. Your post caught my eye because I
had been looking at some similar-but-different problems. I am
evaluating the 'sfio' package from firstname.lastname@example.org.
[ Guido ( and others to whom it may concern):
- you may want to take a look at sfio. It fixes some of the stdio
problems ( like interrupted i/o, allowing writes to read-opened
files, etc. ). There is a different API that stdio-lib, with
some extra neat features, but there is a stdio emulation package
for backwards source compatability. I haven't used it enough yet
to give a report. ]
-Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
-Univ. of Virginia Department of Molecular Physiology and Biological Physics