[mod_python] how do i share variables accross requests?

R. Pelizzi r.pelizzi at virgilio.it
Thu Aug 26 20:59:11 EDT 2004


Jean-Philippe Barrette-LaPierre wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On August 26, 2004 12:12 pm, R. Pelizzi wrote:
   [CUT]
> 
> 
> for session management see:
>    http://www.modpython.org/live/current/doc-html/pyapi-sess.html 
> for "persistance" accross sessions see:
>    http://www.modpython.org/live/current/doc-html/pyapi-cookie.html
> 
>>Thank you
>>Riccardo
>>_______________________________________________
>>Mod_python mailing list
>>Mod_python at modpython.org
>>http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> 
> - -- 
> Jean-Philippe Barrette-LaPierre
> Maintener of curlpp
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
> 
> iD8DBQFBLfTV4k/6r/h0g7kRAoO/AKCsSlIbqtkU3nqL+K1reyC+sgIxZACgjGbv
> YW9RJDfSQ9fXFxdsiizhmEE=
> =rs67
> -----END PGP SIGNATURE-----
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
> 

no. You didn't get the point. Suppose you want to print out how many 
users are browsing the site at the moment. You would have to count the 
active sessions. Unfortunately there's no way to do that. A quick 
workaround would be to use a variable global to all the sessions, add 1 
to it for every new session and register a cleanup function for the 
session that substract 1 to the variable. The variable would then count 
the active sessions, which roughly estimates how many users are browsing 
the site. Now, in this simple example i could just pickle the variable 
and store it on disk using dbm, mysql or whatever. But
1. what about unpickable objects? are all objects pickable?
2. is this a bit inefficient? You would have to read, unpickle and 
repickle the variable every time a new session begins or expires, or 
read and unpickle it on every request!
3. I'm lazy... anybody did this before and can post the code? ^_^


More information about the Mod_python mailing list