[New-bugs-announce] [issue32345] EIO from write() is only fatal if print() contains a newline

Creideiki report at bugs.python.org
Sat Dec 16 04:28:32 EST 2017

New submission from Creideiki <creideiki+pythonbugs at ferretporn.se>:

This is Python 2.7.14 on Gentoo Linux.

I ran into an issue where a program crashes if I run it from a terminal, put it in the background, and then close the terminal too soon. Upstream bug report: https://github.com/micahflee/torbrowser-launcher/issues/298

It seems the cause is that a print() call without a newline ignores the EIO returned by the write() syscall, but if there is a newline in the string, that EIO is suddenly a fatal error.


$ cat fatal.py 
#!/bin/env python2.7
import time

Run this program in the background under strace to see what it does, and while it is sleeping, close its controlling terminal:

$ strace -s 256 -o fatal.log -f ./fatal.py &
[1] 17974

Now look at the strace log:

$ grep write fatal.log
17978 write(1, "A\n", 2)                = -1 EIO (Input/output error)
17978 write(1, "B\n", 2)                = -1 EIO (Input/output error)
17978 write(2, "Traceback (most recent call last):\n", 35) = -1 EIO (Input/output error)
17978 write(2, "  File \"./fatal.py\", line 5, in <module>\n", 41) = -1 EIO (Input/output error)
17978 write(2, "    ", 4)               = -1 EIO (Input/output error)
17978 write(2, "print('B\\nC')\n", 14)  = -1 EIO (Input/output error)
17978 write(2, "IOError", 7)            = -1 EIO (Input/output error)
17978 write(2, ": ", 2)                 = -1 EIO (Input/output error)
17978 write(2, "[Errno 5] Input/output error", 28) = -1 EIO (Input/output error)
17978 write(2, "\n", 1)                 = -1 EIO (Input/output error)

The first print('A') ran and had an EIO error, which was ignored. The second print('B\nC') tried to write 'B', had an EIO error, and crashed. The third print('D') was never attempted.

components: IO
messages: 308468
nosy: Creideiki
priority: normal
severity: normal
status: open
title: EIO from write() is only fatal if print() contains a newline
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list