Message193392
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. |
|
Date |
User |
Action |
Args |
2013-07-20 01:45:51 | Marc.Abramowitz | set | recipients:
+ Marc.Abramowitz, barry, brett.cannon, rhettinger, ncoghlan, belopolsky, pitrou, vstinner, alex |
2013-07-20 01:45:51 | Marc.Abramowitz | set | messageid: <1374284751.72.0.09001882885.issue15805@psf.upfronthosting.co.za> |
2013-07-20 01:45:51 | Marc.Abramowitz | link | issue15805 messages |
2013-07-20 01:45:50 | Marc.Abramowitz | create | |
|