Threads with independant IO streams

Tim Peters tim.one at comcast.net
Thu Mar 13 12:10:30 EST 2003


[Jason Harper]
> Is it possible for multiple Python threads to have their own sys.stdout
> (and other streams), such that plain `print' statements in each thread
> send output to different places?

Probably, but it wasn't designed to.

> I have managed to create a separate sys module for each thread (using an
> import hook much like rexec uses), and can have sys.stdout.write()
> output go to different places, but print output still goes to the stdout
> defined in the 'real' sys module.

The print statement passes the object to be printed to sys.displayhook() for
display.  You could try supplying your own displayhook function.






More information about the Python-list mailing list