[mod_python] Problem with caching

Aaron Scott Hildebrandt aaron.hildebrandt at gmail.com
Fri Apr 3 19:15:32 EDT 2009


This is my first time working with mod_python. One thing that I wasn't
prepared for was dealing with persistence. I have an app that I'm
trying to make work through mod_python, but everything goes to hell
the moment there's multiple users.

The way it's supposed to work is like this:

The page is accessed. A number of variables are loaded. The user
changes some of the variables, the changes are saved to a pickled
file. The next time the user loads the page, those saved variable
values are loaded back in.

The problem is, as soon as the variables have been changed, if anyone
accesses the page in the near future, they'll see those changed
variables. Here's where it really starts driving me insane: a lot of
the time, that second user will see the changed variables even if he
has his own pickled file that has been loaded and was supposed to
overwrite them.

For example:

I have a file with the variable "x = 0". A user changes the value to
"x = 5", and that change is saved to a pickled file (tied to a session
ID).

A second user accesses the page, where the value is now "x = 5". He
changed the value to "x = 10". This is saved to his own pickled file.

The first user returns to the site. Since he's returning, his pickled
file, with "x = 5", is loaded. Except, when he looks at the data, he
sees "x = 10", even though that variable was supposed to have been
changed to "5" when his file loaded.

A more direct code example:

The module lab.game has the class InitGame, which contains "daemons =
{}". There's an instance of this class called "settings".

A user runs the code, resulting in some values in "daemons":
"{'berry2': 3, 'berry3': 5, 'berry1': 7}". These are pickled. The next
user runs the code. I put this in to make sure "daemons" is getting
reset:

        req.write(str(lab.game.settings.daemons))
        del lab.game.settings
	try: req.write(str(lab.game.settings.daemons))
	except: req.write("failed")
        lab.game.settings = lab.game.InitGame()
        req.write(str(lab.game.settings.daemons))

Okay, that should wipe out any of the values and leave us with a clean
slate, right? But no, it doesn't. This is the output:

        {'berry2': 3, 'berry3': 5, 'berry1': 7}failed{'berry2': 3,
'berry3': 5, 'berry1': 7}

So, even if I try deleting the variable itself, the moment I try to
reinitialize it, the old values return.

Does anyone know what I'm doing wrong, or if there's any way I can
just kill mod_python's persistence altogether?

Thanks,
Aaron

-- 
Aaron Scott Hildebrandt
andcuriouser.com


More information about the Mod_python mailing list