[Python-bugs-list] [ python-Bugs-421728 ] readline returns '' when interrupted

noreply@sourceforge.net noreply@sourceforge.net
Sat, 05 May 2001 15:37:22 -0700


Bugs item #421728, was updated on 2001-05-05 15:37
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=421728&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: readline returns '' when interrupted

Initial Comment:
When file.readline() is waiting for a line to be read,
and is interrupted by a handled signal, it returns the
empty string, ''. It does not raise a IOError exception
(interrupted system call), as I would expect. Although
the documentation is not explicit about what the
behavior should be in this case, returning '' is a bad
idea since it looks just like an end of file, even
though there is more data that can be read.

There is some discussion of this in the python-list
mailing list -- the thread is "Signals and readline()".
In that thread, Jeff Epler advanced a theory as to a
possible source change to fix this.

It is easy to reproduce, and produces the same behavior
on both Linux (Mandrake 7.2) and FreeBSD (4.0). Using
Python 2.0.

To reproduce:

Enter this Python program interactively (under Unix):

import sys, os, signal
print os.getpid()
signal.signal(signal.SIGUSR2, lambda *x: None)
sys.stdin.readline()

>From another shell, send SIGUSR2 to the printed PID:

kill -SIGUSR2, <pid>

The readline will return ''.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=421728&group_id=5470