homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients martin.panter, neologix, serhiy.storchaka, vstinner
Date 2015年03月03日.11:41:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1425382904.46.0.335166118733.issue23570@psf.upfronthosting.co.za>
In-reply-to
Content
> Do you want to modify IOBase.__exit__ to ignore I/O errors in close()?
Nope. On files, you want to want to know if your data has been fully written. For a subprocess, it's different. You only expect best effort.
The BrokenPipeError exception is raised by Python when an OS function fails with EPIPE. This exception has the same purpose than the SIGPIPE signal: warn the application that it's now useless to send more data, the consumer will ignore it. By the way, since Python checks the result of *all* OS functions, SIGPIPE is simply ignored. SIGPIPE and EPIPE have the same purpose.
In the subprocess module, if we get BrokenPipeError, it means that the child process stopped reading from stdin (closed it or the process already exited).
Popen.communicate() must close stdin, so why would we pass BrokenPipeError to the caller? It's useless, we just stop writing and close the pipe.
Since Popen.__exit__() also closes stdin, I use the same rationale: it useless to pass BrokenPipeError to the caller. The caller expects that the process exited.
Anyway, we closed all pipes, it's not more possible to communicate with the child process. The following example displays "is proc stdin closed? True":
---
import subprocess, sys
args = [sys.executable, '-c', 'pass']
proc = subprocess.Popen(args, stdin=subprocess.PIPE)
try:
 with proc:
 proc.stdin.write(b'x' * (2**20))
except BrokenPipeError:
 pass
print("is proc stdin closed?", proc.stdin.closed)
---
See also: "Why does SIGPIPE exist?"
https://stackoverflow.com/questions/8369506/why-does-sigpipe-exist 
History
Date User Action Args
2015年03月03日 11:41:44vstinnersetrecipients: + vstinner, neologix, martin.panter, serhiy.storchaka
2015年03月03日 11:41:44vstinnersetmessageid: <1425382904.46.0.335166118733.issue23570@psf.upfronthosting.co.za>
2015年03月03日 11:41:44vstinnerlinkissue23570 messages
2015年03月03日 11:41:44vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /