[mod_python] Interpreters and global names

Graham Dumpleton graham.dumpleton at gmail.com
Tue Aug 28 18:04:12 EDT 2007


Apache on UNIX is a multi process web server. Read:

  http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel

Graham

On 29/08/07, Rolf van de Krol <mod_python at rolfvandekrol.nl> wrote:
> Hi everybody at this list,
>
> I've got a problem. To me it seems quite complex so explaining it takes
> some code to write. But i'm a total newbie to mod_python. I've read the
> documentation, I understand it, I managed to setup a running mod_python
> installation and I can write some simple applications with it. That's it.
> So, my apologies for the amount of code in the message,  I hope you can
> bring the effort to read it to understand my problem. I enclosed python
> code in <code> tags to show where the code begins and ends.
>
> I've set up two VirtualHosts with the following directives in
> httpd.conf. (I changed some names, because the domainnames used for this
> are not to be published.)
>
> NameVirtualHost *:80
> <VirtualHost *:80>
>     ServerName domain1.ext
>     ServerAdmin admin at domain1.ext
>     <Location />
>         Order Allow,Deny
>         Allow from all
>
>         SetHandler mod_python
>         PythonInterpreter domain1interpreter
>         PythonHandler D:/main.py
>         PythonDebug On
>     </Location>
> </VirtualHost>
>
> <VirtualHost *:80>
>    ServerName admin.domain1.ext
>    ServerAdmin admin at domain1.ext
>      <Location />
>        Order Allow,Deny
>        Allow from all
>              SetHandler mod_python
>        PythonInterpreter domain1interpreter
>        PythonHandler D:/radmin.py
>        PythonDebug On
>    </Location>
> </VirtualHost>
>
> As you can see, they both share the same interpreter. The setup works.
> With the following python code in main.py and radmin.py they both print
> the same name.
>
> <code>
> from mod_python import apache
> def handler(req):
>     req.content_type = 'text/plain'
>     req.write(req.interpreter)
>     return apache.OK
> </code>
>
> I changed main.py to the following code:
>
> <code>
> from mod_python import apache
> import collections
>
> def handler(req):
>     if not globals().has_key('aPool'):
>         aPool = collections.deque()
>         global aPool
>     else:
>         global aPool
>
>     # code to use aPool and print some output
> </code>
>
> aPool is used to create a database connection pool, but that's not
> important to the problem. The code above works fine.
>
> I change radmin.py to the following:
>
> <code>
> from mod_python import apache
> import collections
> import pprint
>
> def handler(req):
>     req.content_type = 'text/plain'
>     req.write(pprint.pformat(globals()))
> </code>
>
> What I expected was that I could find aPool in the output of radmin.py.
> But I couldn't. It just isn't there. It seems that the global names
> aren't as global as they seem to be. Is there a way to make variables
> set in main.py accessable to radmin.py?
>
> I hope any of you knows the answer.
>
> Rolf van de Krol
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list