[Python-Dev] Signal-resistant code (was: Two random and nearly unrelated ideas)

Jack Jansen Jack.Jansen@oratrix.com
Wed, 4 Sep 2002 13:45:30 -0700

On woensdag, sep 4, 2002, at 11:51 US/Pacific, Oren Tirosh wrote:
> When an I/O operation is interrupted by an unmasked signal it returns
> with errno==EINTR.  The state of the file is not affected and repeating
> the operation should recover and continue with no loss of data.
I'm not sure about modern unixen (it's been a long time since I was 
interested in such lowlevel details) but historically this has been one 
complete mess.

Aside from some unix variations that basically didn't do restart at all 
there have always been problems with signal restart semantics. For 
sockets and various devices (raw ttys, I think) you could definitely 
lose data.

Hmm, and when I think of it I don't think it's even possible to restart 
safely. What if I do a read() on a socket, and I request more bytes 
than the available physical memory (but less than VM, of course)? The 
kernel simply doesn't have anywhere to store the bytes other than my 
buffer, and if it has to return EINTR then >POOF< these bytes are gone