Module caching

A

Aaron Scott

Is there a way to make a Python app running in mod_python with zero
persistence? I have an app that should be resetting its variables
every time you access it, but sometimes -- and only sometimes -- the
variables persist through a couple refreshes. They'll even persist
through multiple browsers, so I know it's a Python issue and not a
browser caching issue.

Any assistance would be appreciated.
 
A

Aaron Scott

Okay, I'm at my wit's end. I have a Python app, running via
mod_python. There are variables in this app that, when changed, save
their changes to a pickled file tied to a session ID. Then, when the
page is accessed again, the variables are loaded from the respective
file.

But, when one user uses the page and a number of variables are
changed, these changes persist, even if I try to load the saved values
over them. So, if my Python file has a value of "5", the "custom
values" file has a value of "10", but a user does something that
changes the variable to "20", the next user who accesses the page with
see the value as "20", even if their "custom values" file tries to set
it differently.

If anyone has experience with mod_python, either drop me a message
here or e-mail me at aaron(at)manlab.com. I'd really appreciate some
help with this.
 
A

Aaron Scott

Huzzah, another post.

I just discovered that even physically deleting the variable doesn't
work.

The module storylab.game has the class InitGame, which contains
"daemons = {}".

A user runs the code, resulting in some values in "daemons":
"{'berry2': , 'berry3': , 'berry1': }". 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
req.write(str(lab.game.settings.daemons))
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?

{'berry2': , 'berry3': , 'berry1': }failed{'berry2': , 'berry3': ,
'berry1': }

Oh, you'd be so lucky.

Why? WHY? Why does these values persist? They persist if I change
them, they persist if I delete them.

Help... please :(
 
A

Aaron Scott

        req.write(str(lab.game.settings.daemons))
        del lab.game.settings
        req.write(str(lab.game.settings.daemons))
        lab.game.settings = lab.game.InitGame()
        req.write(str(lab.game.settings.daemons))

Sorry, that should have been:

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

Aaron Scott

are you an experienced python programmer?
Yeah, I'd link to think I'm fairly experienced and not making any
stupid mistakes. That said, I'm fairly new to working with mod_python.

All I really want is to have mod_python stop caching variables. This
seems like it should be easy enough to do, but I can't for the life of
me find information on how to do it.

Aaron
 
J

Jon Clements

Yeah, I'd link to think I'm fairly experienced and not making any
stupid mistakes. That said, I'm fairly new to working with mod_python.

All I really want is to have mod_python stop caching variables. This
seems like it should be easy enough to do, but I can't for the life of
me find information on how to do it.

Aaron

Umm... Well, mod_python works for long running processes that don't
really store data, but return it on demand... so keeping module level
variables around is going to be a gotcha.

It's a kludge, but setting MaxRequestsPerChild to 1 in the Apache
config basically forces a reload of everything for every request...
that might be worth a go -- but it's nasty...

Cheers,

Jon.
 
G

Graham Dumpleton

Umm... Well, mod_python works for long running processes that don't
really store data, but return it on demand... so keeping module level
variables around is going to be a gotcha.

It's a kludge, but setting MaxRequestsPerChild to 1 in the Apache
config basically forces a reload of everything for every request...
that might be worth a go -- but it's nasty...

They may as well use CGI then. Personally I would never recommend
MaxRequestsPerChild be set to 1.

Anyway, this person also posted on mod_python list. One of the things
I highlighted there was that mod_python for some configurations is
multithreaded and as such they may not be properly protecting
variables if they are storing them at global scope. They haven't
responded to any comments about it on mod_python list. They were also
told to read:

http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel

Graham
 
A

Aaron Scott

Anyway, this person also posted on mod_python list. One of the things
I highlighted there was that mod_python for some configurations is
multithreaded and as such they may not be properly protecting
variables if they are storing them at global scope. They haven't
responded to any comments about it on mod_python list. They were also
told to read:

 http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreter....

Graham

Thanks, Graham. Sorry I didn't respond -- it's crunch time here, so I
was pulled off the project for a couple days to help with something
else. I just didn't have time to catch up.

In the end, we decided to convert everything from mod_python to CGI,
which ended up getting us the functionality we were looking for. For
development, MaxRequestsPerChild was already set to 1, but this didn't
solve any of the variable caching issues.

Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,293
Messages
2,571,501
Members
48,189
Latest member
StaciLgf76

Latest Threads

Top