[mod_python] Using shared memory to do global persistence

VanL vlindberg at verio.net
Thu Jun 26 14:44:24 EST 2003


Jonathan Gardner wrote:

> The problem I see now: How to communicate between all of the processes 
> that
>
>there are shared objects available, and detail where those shared objects 
>are? I don't think it is possible to create shared objects via mod_python 
>before the processes are seperated. Even if it was, is it possible to 
>transfer references to those shared objects to each process?
>
>The only solution I see right now is to have some central repository that any 
>process can access and declare the existence of shared objects, their 
>location, and whatever else is needed. Other processes can read the 
>repository and find currently existing shared objects by a unique string.
>

I think that the nicest solution (in terms of API, at least) would be to 
have an explicit namespace that is instantiated when mod_python is first 
loaded.  Applications could then access this shared namespace by 
importing it; anything declared in the namespace would be automatically 
shared.

For example.

[in code_run from mod_python]

from mod_python import apache.shared as shared

shared.myvar = 'something here'

if not hasattr(shared, 'anothervar'): shared.anothervar = 'something else'

it could be an option declared in the httpd.conf, optionally specifying 
a type of backing store:

<PythonOption shared-memory> # just uses a piece of memory
or
<PythonOption shared-memory mmapstorage file="shared.dat">
or
<PythonOption shared-memory berkeleystorage file="shared.db">
or
<PythonOption shared-memory zodbstorage file="shared.zodb">

VanL



More information about the Mod_python mailing list