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

Antoon Pardon apardon at forel.vub.ac.be
Fri Jul 14 06:17:42 EDT 2006


On 2006-07-13, notanotheridiot <johannes.wollard at gmail.com> wrote:
> 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.

What do you mean by this?

Do you mean that the data that is passed between the two processes
is so little it is all buffered until the second process finishes,
at which time the first process receives it all?

It so and this is a problem then maybe the pty module can help you.

-- 
Antoon Pardon



More information about the Python-list mailing list