Message153320
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. |
|
Date |
User |
Action |
Args |
2012-02-14 03:40:15 | Jeremy.Fishman | set | recipients:
+ Jeremy.Fishman, terry.reedy, ulidtko |
2012-02-14 03:40:15 | Jeremy.Fishman | set | messageid: <1329190815.43.0.809543975922.issue11380@psf.upfronthosting.co.za> |
2012-02-14 03:40:14 | Jeremy.Fishman | link | issue11380 messages |
2012-02-14 03:40:14 | Jeremy.Fishman | create | |
|