Re: Output disappears when using interrupt key

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Wed, 14 Apr 1993 14:39:39 -0400

xOn Apr 14, 10:16, Jaap Vermeulen wrote:
>
> I'm seeing the following anomaly. When executing the following
> statements:
>
> import sys
> try: sys.stdin.readline()
> except: print 'OK'
>
> and generating a keyboard interrupt while readline() is waiting for
> input, will *not* print the 'OK' on my system.
>
> [ ... alternate example deleted ]
>
> My question is: is this platform specific? Do other people experience
> the same problem? Any other words of wisdom?
>

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
clause.

[ I also just tried SunOS 4.1 python sys.version 0.9.4 and got the same
results. ]

>>> def try1():
... try: sys.stdin.readline()
... except: print ' -OK.'
...
>>> try1()

'\012'
>>> try1()
^C^C^C^C^Cxxx

-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 netlib@research.att.com.

[ 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