[mod_python] idea for PSP

Byron Ellacott bje at apnic.net
Thu Feb 26 09:36:11 EST 2004


On Wed, 2004-02-25 at 23:36, Gregory (Grisha) Trubetskoy wrote:
> On Wed, 25 Feb 2004, vincent delft wrote:
> The problem is that in a multithreaded configuration, there is only one
> sys.stdout for multiple requests, so one thread cannot assign to it
> without affecting others :-)

Assuming there is some way to get the current thread, you /COULD/ do:

class tstdout:
    def __init__(self):
        self.threads = {}
    def add_thread(self, thread_id, stream):
        self.threads[thread_id] = stream
    def write(self, data):
        self.threads[current_thread_id()].write(data)
    # Other methods of sys.stdout as appropriate

save = sys.stdout
sys.stdout = tstdout()
sys.stdout.add_thread(None, save)

There's not much good you can say about what this would do to
efficiency, though. :)

-- 
bje


More information about the Mod_python mailing list