[mod_python] Session management

Jim Gallacher jg.lists at sympatico.ca
Wed Nov 2 11:06:02 EST 2005


Ognen Duzlevski wrote:
> Hi all,
> 
> I read this paragraph from the BaseSession docs:
> 
> "id is an optional session id; if provided, such a session must already 
> exist, otherwise it is ignored and a new session with a new sid is 
> created. If sid is not provided, the object will attempt to look at 
> cookies for session id. If a sid is found in cookies, but it is not 
> previously known or the session has expired, then a new sid is created. 
> Whether a session is ``new'' can be determined by calling the is_new() 
> method."
> 
> Does this imply that I can do the following:
> 
> create a Session() object and it will somehow decide where to go (say 
> dbm or memory)
> on the next visit to the same page I should be able to do ms = 
> Session.Session(req) and ms.is_new() will tell me that this session is 
> not new because it was looked up (through the cookie pysid I am 
> assuming) and found in the persistant storage (like for dbm or memory, 
> either way)?

That's pretty much it. The important thing is that you *must* call 
ms.save() to save your session data to the persistent store. Otherwise 
each visit to the same page will generate a new sid.

The default store is platform dependant depending on which apache-mpm 
you are using. In 3.2 you can specify the default using the 
"PythonOption session session_class_name" directive where 
session_class_name is one of MemorySession, DbmSession or FileSession.

Jim



More information about the Mod_python mailing list