Jeremy Fishman <[email protected]> added the comment:
The behavior under question here is how the interpreter handles a broken pipe
during shutdown. The following code behaves as expected when either (a) the
process receives a SIGINT or (b) the output pipe is closed
import sys
try:
while True:
print 'y'
except KeyboardInterrupt:
sys.exit(130)
except (IOError, OSError):
sys.exit(141)
However, in the case of a SIGINT sent to the entire process group e.g. from a
shell prompt, the interpreter may receive the SIGINT before detecting the
broken pipe. In this case, the interpreter prints an error somewhere during
the SIGINT handler or subsequent shutdown.
In Python 2.4.6 and 2.5.2 the error is
close failed: [Errno 32] Broken pipe
In Python 2.7.2 the error is
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
In Python 3.2 the error is
Exception IOError: IOError(32, 'Broken pipe') in <_io.TextIOWrapper
name='<stdout>' mode='w' encoding='UTF-8'> ignored
I have not succeeded in triggering the error in Python 3.1.2, despite ensuring
the signal arrived before the next write(2) call after the output pipe was
closed. I have attached some straces, but this difference is probably spurious
unless reproduced with one of the later bugfix 3.1 releases.
In all versions, the program properly terminates with code 130, or 141 if the
write(2) error occurs first.
I would say the bug here if any is inconsistent behavior, though that isn't
surprising between major versions. The 2.7 error message is the only
misleading one - stderr was never "lost", and we don't really care about
sys.excepthook here.
----------
nosy: +Jeremy.Fishman
Added file: http://bugs.python.org/file24517/python-sigint_and_epipe_straces.txt
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue11380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com