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 Marc.Abramowitz
Recipients Marc.Abramowitz, alex, barry, belopolsky, brett.cannon, ncoghlan, pitrou, rhettinger, vstinner
Date 2013-07-20.01:45:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374284751.72.0.09001882885.issue15805@psf.upfronthosting.co.za>
In-reply-to
Content
As it happens, I wrote a similar context manager to Victor's recently for a setup.py because I wanted to suppress compiler errors that are output to the console by distutils.ccompiler.CCompiler.has_function. As Victor mentioned, for this to work with subprocesses, you need to go a little more low-level and mess around with file descriptors. Here's my function:

http://marc-abramowitz.com/archives/2013/07/19/python-context-manager-for-redirected-stdout-and-stderr/

(Maybe distutils.ccompiler.CCompiler.has_function should redirect its own output automatically, but that's another issue)

But then I got to thinking that it could be made a bit more powerful and the syntax could be a little nicer. So I have this code that I'm experimenting with:

https://gist.github.com/msabramo/6043474

But critiquing my own function, I wonder if it's trying to do too much in one function and it's using keyword arguments where it could be using the with statement better. So I might like Nick's API better.
History
Date User Action Args
2013-07-20 01:45:51Marc.Abramowitzsetrecipients: + Marc.Abramowitz, barry, brett.cannon, rhettinger, ncoghlan, belopolsky, pitrou, vstinner, alex
2013-07-20 01:45:51Marc.Abramowitzsetmessageid: <1374284751.72.0.09001882885.issue15805@psf.upfronthosting.co.za>
2013-07-20 01:45:51Marc.Abramowitzlinkissue15805 messages
2013-07-20 01:45:50Marc.Abramowitzcreate