stdout/stderr for only one thread in a multithreaded python app

notanotheridiot johannes.wollard at gmail.com
Thu Jul 13 13:21:18 EDT 2006


Hi-

I'm trying to exec some arbitrary code in one thread of an application
and read anything it prints to stdout or stderr in another thread. My
question is how?

I've tried changing sys.stdout, but that changes stdout for the whole
application, not just that one thread, which means that any status
updates that I DO want printed to stdout don't get printed.

I've also tried running the code in a seperate process in a new python
interpreter using popen* but I can't read data from stdout until the
program has finished.

Is there some way of passing an overridden value of sys.stdout/stderr
to the exec environment?
(again, I've tried the obvious: exec code in {"sys.stdout": my_stdout}
)

Hoping someone will know something...

Johannes Woolard




More information about the Python-list mailing list