[mod_python] idea for PSP

vincent delft vincent_delft at yahoo.com
Wed Feb 25 21:46:02 EST 2004

I've think about your feedback. And, now I'm confused.
Sorry to come back with this, but I would like to

If you execute the following code, you will get a
counter in each file like expected because each thread
has his own buffer.

import time
from threading import Thread
import sys
def funct(i):
     fid=open('/tmp/tt%s.tt' % i,'w')
     for j in xrange(50):
        print i,j,
for i in xrange(50): Thread(target=funct,

Thus, if we redirect the stdout to "req" in each
thread we should not have conflicts.

The common between threads is not sys.stdout but the
console (or the log file) on which stdout is linked.

--- "Gregory (Grisha) Trubetskoy"
<grisha at modpython.org> wrote:
> On Wed, 25 Feb 2004, vincent delft wrote:
> > adapt the psp.py code by using an "exec" (instead
> of eval) and redirect
> > sys.sdtout to req.write just before the execute.
> "print" is what the original mod_psp.c used,
> actually.
> 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 :-)
> Grisha

Do you Yahoo!?
Get better spam protection with Yahoo! Mail.

More information about the Mod_python mailing list