[mod_python] Safety of using __builtins__ for per-request information?

Guy Davis davis at guydavis.ca
Tue Sep 2 11:10:47 EST 2003


Hi all,

I'm writing a custom handler using the mod_python.cgi_handler as a guide 
on Apache 1.3 with mod_python 2.7.  Unfortunately, our old CGI makes use 
of certain super-global variables that are not easily done away with.  
I've been able to get this to work by having the handler set the global 
vars into the __builtins__ dictionary.  Then various CGI scripts can 
pull them from __builtins__ when needed. I know using __builtins__ in 
this fashion is not recommended as it's a bit of a hack.

My question is whether storing per-request information in __builtins__ 
is risky due to concurrency reasons.   Put another way, is __builtins__ 
shared between concurrent requests?  For example, person A hits a page 
and the handler stores __builtins__['foo'] = 'bar'.  At nearly the same 
time person B hits a page and the handler stores __builtins__['foo'] = 
'bar2'.  After this occurs, the CGI for person A retrieves 
__builtins__['foo'].  Will the result always be 'bar' or will 'bar2' 
sometimes be returned depending on the timing?

Will the behaviour be any different under Apache 2 and mod_python 3?

Thanks in advance for any responses.

Guy Davis                 http://www.guydavis.ca





More information about the Mod_python mailing list