[Web-SIG] multi-threaded or multi-process wsgi apps

Ian Bicking ianb at colorstudy.com
Thu Nov 29 00:44:01 CET 2007


Chris Withers wrote:
> Ian Bicking wrote:
>> At least in Pylons apps, configuration is setup during instantiation. 
>> Configuration is generally copyable (consisting of stuff like strings, 
>> not open file objects), so it can be cloned across processes easily. 
> 
> I can understand sharing across threads, but how do you share across
> processes?

Well, with a forking server like flup it is just inherited from the 
fork.  Otherwise, I'm not sure.  The config is pickleable.  Usually I'd 
pass a reference to the config file, or config source, which are 
probably simple strings.

>>> The second is a problem I see an app I'm working on heading towards. 
>>> The app has web-alterable configuration, so in a multi-threaded and 
>>> particular multi-process environment, I need some way to get the 
>>> other threads or processes to re-read their configuration when it has 
>>> changed.
>>
>> In Paste/Pylons the configuration is stored in the environment (which 
>> is per-request), and put into a threadlocal object for access.  
> 
> Again, how about across processes?
> And if the configuration changes once the app is up and running, how do 
> you propogate changes to all the other app processes?

Generally you'd want to kill all the worker processes and start over. 
If you have a reasonable way to do that (and I think mod_wsgi would give 
you a reasonable way to do that), restarting the process is always 
cleanest.  I believe even something like Apache's "graceful" 
restart/reload just restarts the server, while letting existing requests 
finish.

-- 
Ian Bicking : ianb at colorstudy.com : http://blog.ianbicking.org


More information about the Web-SIG mailing list