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

N

notanotheridiot

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
 
A

Antoon Pardon

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top