Here's a simple Python script:
import subprocess with open('hi.txt', 'w') as f: subprocess.Popen(['echo', 'Hello'], stdout=f).wait()
Here's what it does:
$ python2.7 hi.py $ cat hi.txt Hello
And here's what happens if you try to use the trace module to trace the execution:
$ python2.7 -m trace --trace hi.py (lots of trace output omitted)
So far so good, but take a look at hi.txt:
$ cat hi.txt subprocess.py(1170): _dup2(errwrite, 2) --- modulename: subprocess, funcname: _dup2 subprocess.py(1164): if a == b: subprocess.py(1166): elif a is not None: ... 154 lines of unexpected trace output omitted ... os.py(379): try: os.py(380): func(fullname, *argrest) Hello
The tracing hook installed by trace.py survives the os.fork() and interferes with subprocess output redirection. Now you know.
Imagine what this does to scripts that execute shell commands and try to parse their output.
Who wants to file a bug and/or provide a patch? I'm afraid I don't have enough round tuits...