[mod_python] how do i share variables accross requests?

mike bayer mike_mp at zzzcomputing.com
Thu Aug 26 12:36:27 EDT 2004


just curious....what kind of global variable, shared across all processes,
would you be *writing* to ?   If you are just caching pre-loaded data from
a database or something, you can pre-load whatever is appropriate before
the server starts its child processes, and then have each fork cache
additional data as it needs to in its fork-local copy of the cache.

but also im sure theres a lot of libraries (yah like dbm) you could use as
well for this, probably worth it to try them before deciding that its less
efficient than IIS/ASP ...




> You probably have encountered this feature in other application
> frameworks... i remember i was using it in ASP, it was called the
> Application Object. You could store variables (ints, strings, objects)
> in it and every request could read and write them thread-safely. A
> simple example using this feature would be a user-online counter.
> Every request would check if the session is new. If it is, increment the
> counter and register a cleanup function for the session to decrement it.
> Now, how do i implement it in python?
> global variables, as far as i've understood, are not global to the
> server, just to the child process spawned by the server, so they cannot
> be used.
> Do i really have to pickle what i want to share and write it on disk
> using dbm, mysql or such? Wouldn't this be terribly inefficient,
> pickiling and unpickling every request?
> Does anybody have already implemented something similar and can post the
> code?
>
> Thank you
> Riccardo
> _______________________________________________
> 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