On 11 Sep 2007, at 21:11, bubblboy wrote:
>  $ grep threadsafe *
>  utils.py:re_compile = memoize(re.compile) #@@ threadsafe?

I don't know why this would or wouldn't be threadsafe, but it should  
disappear altogether. re.compile is already memoized. Rly! (Indeed,  
check sre.py.)

>  utils.py:    **WARNING:** Not threadsafe!
>  utils.py:        # Not threadsafe!

This is CaptureStdout.

I propose thus:
We set up a global (utils.py maybe) API for having thread-local  
stdouts. We can probably already do this with threadeddict, I think.  
Then we reimplement webapi.py's _capturedstdout() and _outputter  
stuff in terms of this, as well as utils.py's CaptureStdout. That'll  
give us both threadsafety and much better uniformity.

> So.. what exactly does this imply? I am not very ("absolutely not")
> familiar with python threads, but when you specify the number of
> concurrent code.py processes in the lighttpd configuration file,  
> can it
> only be "1"? Or does that have nothing to do with it?

That doesn't have to do with it. Anything (pretty much) is multi- 
process-safe. The problem is when you have multiple threads in the  
same process (i.e. multiple bits of code executing concurrently in  
the same interpreter, able to potentially access the same objects at  
the same time). Problems with threadsafety can arise when two  
different threads try to do something to the same object at once. For  
instance, CaptureStdout is not threadsafe because one thread can  
start an instance, and then, before it has finished, another thread  
can start another instance (which replaces sys.stdout *again*) and  
interfere with the first one. Locks can solve problems like this, but  
I think having thread-local objects would be better in this situation.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to