By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,443 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,443 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 2006-07-13, notanotheridiot <jo**************@gmail.comwrote:
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
Jul 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.