[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
understand.

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')
     sys.stdout=fid
     for j in xrange(50):
        print i,j,
        time.sleep(0)
     fid.close()
for i in xrange(50): Thread(target=funct,
args=(i,)).start()


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.
http://antispam.yahoo.com/tools


More information about the Mod_python mailing list