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 xmorel
Recipients xmorel
Date 2021-05-17.12:32:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621254753.52.0.230769289673.issue44157@roundup.psfhosted.org>
In-reply-to
Content
In 3.4 (resp. 3.5), `redirect_stdout` and `redirect_stderr` were added to provide easy and reentrant stream redirection. Although that is documented, it seems like a waste that they only redirect the high-level `sys.std*`  streams: those are already pretty easy to redirect by simply setting the corresponding attribute, which is essentially what the contextmanager does. However,

* that does not work if the writer has imported the original stream object (`from sys import stderr`)
* that does not work if the writer bypasses or is not aware of the Python layer e.g. a native library

In that case, the user still has to deal with dup/dup2 dances in order to redirect the underlying fds, which is significantly more error-prone (and verbose) than intercepting the high-level `sys.std*` ever was.

On the other hand, it's also less expressive as it requires an actual fd, rather than a Python-level file-like object. So I can understand not doing it by default.

But still, I think I feel like it'd be very useful to either expand  the existing context managers to perform fd redirection, or have a separate context manager able to redirect arbitrary fds.
History
Date User Action Args
2021-05-17 12:32:33xmorelsetrecipients: + xmorel
2021-05-17 12:32:33xmorelsetmessageid: <1621254753.52.0.230769289673.issue44157@roundup.psfhosted.org>
2021-05-17 12:32:33xmorellinkissue44157 messages
2021-05-17 12:32:33xmorelcreate