[Python-bugs-list] [ python-Bugs-421728 ] readline returns '' when interrupted
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 06 Dec 2001 07:26:45 -0800
Bugs item #421728, was opened at 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: Closed
Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Michael Hudson (mwh)
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 ''.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-06 07:26
Message:
Logged In: YES
user_id=6380
Thanks for doing this, Michael!!!
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2001-12-06 07:05
Message:
Logged In: YES
user_id=6656
Hmm. Works for me.
Looks like it was fixed by patch #441229 which was applied
by Guido on 2001/08/09 in revision 2.117 of
Objects/fileobject.c.
Closing. (I'll get the "open & unassigned" bugs on one page
soon :)
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=421728&group_id=5470