STINNER Victor added the comment: Patch version 2:
* check if the stream was already "closed" (see below and comment in the patch) * first replace stream and then close it and DECREF the object * don't close stdin anymore > 1. Is there a reason only name is closed, not dunder_name? (Josh's question, > but I'm interesting too). Fixed. > 2. Is it worth to first replace standard streams with "standard printers", > and then close original streams? This allows to log warnings from closing > streams. Fixed. > 3. "standard printers" are used at startup and at shutdown. Can we reuse some > code? I looked at the code creating standard printer during Python startup: it's just a few lines and it doesn't handle the case when stdout/stderr is already open. I don't think that it's worth to reuse code. Anyway, with my new patch, the code is much more complex to handle the case if stderr and/or __stderr__ is "closed" (is NULL, None, getting closed attribute raises an error, or closed attribute is false). > 4. Daemons close standard streams and fileno(stdout) can return unrelevant > value. Fixed. ---------- Added file: http://bugs.python.org/file42349/replace_stdio-2.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26642> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com