Sessions interfering with each other (CherryPy 3.1)

7 views
Skip to first unread message

Jason

unread,
Oct 15, 2008, 3:52:41 AM10/15/08
to cherrypy-users
I have two separate web apps running on the same server, residing in
different directories and intended to run on different ports (8080 and
8040). Under CP 3.0, I just had all the site initialisation and config
in separate files ('server.py') for each app, containing the global
config and engine and server startup. Both apps require users to
login, and keep sessions for the users' login.

Basically, the 'server.py' files both contain (I've omitted various
details, and the port value changes):

if __name__ == '__main__' :
global_conf = {

'global' : {

'server.socket_port' : 8040,

'server.socket_host' : ip_address,

'server.thread_pool' : 10,

'server.environment' : "production",

'log.screen' : True,

'log.error_file' : "site.log",

'engine.autoreload_on' : False,

'engine.autoreload_frequency' : 10,

'tools.sessions.on' : True,

'tools.sessions.timeout' : 1440

}

}


app1_conf = {
'/' : {
'tools.staticdir.root' : this_directory},
'/favicon.ico' : {
'tools.staticfile.on' : True,
'tools.staticfile.filename' : os.path.join(this_directory,
"img/
favicon.ico")},
'/css' : {
'tools.staticdir.on' : True,
'tools.staticdir.dir' : "css"},
'/img' : {
'tools.staticdir.on' : True,
'tools.staticdir.dir' : "img"}}

cherrypy.config.update(global_conf)
cherrypy.tree.mount(HomePage(this_directory), '/', app1_conf)

#### 3.0

#cherrypy.server.quickstart()

#cherrypy.engine.start()
####



#### 3.1

cherrypy.engine.start()
cherrypy.engine.block()
####

When I upgraded to 3.1 (and after changing those lines pertaining to
engine and server startup), suddenly the app sessions interfered with
each other. After logging in to one app, reloading a page from the
other app in the same browser cause the user to be logged out of the
first (even if they weren't logged in to the second). It all works
fine if I use different browsers.

I realise that there was some server/engine separation changes from
3.0 to 3.1, but I can't find any detailed documentation on how this
affects sessions. (In fact, I can't really find any on the sessions
tool at all.)

I would appreciate any pointers on how to adapt this setup for the 3.1
changes.

Cheers,
Jason

jdd

unread,
Oct 15, 2008, 1:58:08 PM10/15/08
to cherrypy-users
perhaps try adding

'tools.sessions.on': True,
'tools.sessions.storage_type':"file",
'tools.sessions.storage_path':
os.path.join(current_dir,'data','sessions')

or similar to both apps?

Jason

unread,
Oct 19, 2008, 9:25:31 PM10/19/08
to cherrypy-users
Unfortunately I just get the evil red text upon login:

Traceback (most recent call last):
File "c:\Python25\Lib\site-packages\cherrypy\_cprequest.py", line
609, in respond
self.hooks.run('before_finalize')
File "c:\Python25\Lib\site-packages\cherrypy\_cprequest.py", line
98, in run
hook()
File "c:\Python25\Lib\site-packages\cherrypy\_cprequest.py", line
58, in __call__
return self.callback(**self.kwargs)
File "c:\Python25\Lib\site-packages\cherrypy\lib\sessions.py", line
565, in save
cherrypy.session.save()
File "c:\Python25\Lib\site-packages\cherrypy\lib\sessions.py", line
125, in save
self._save(expiration_time)
File "c:\Python25\Lib\site-packages\cherrypy\lib\sessions.py", line
334, in _save
pickle.dump((self._data, expiration_time), f)
File "C:\Python25\lib\copy_reg.py", line 69, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle module objects

Module objects, huh?
Reply all
Reply to author
Forward
0 new messages