Keep persistent variables in memory between runs of Python script

Is there any way of keeping a result variable in memory so I don’t have to recalculate it each time I run the beginning of my script?
I am doing a long (5-10 sec) series of the exact operations on a data set (which I am reading from disk) every time I run my script.
This wouldn’t be too much of a problem since I’m pretty good at using the interactive editor to debug my code in between runs; however sometimes the interactive capabilities just don’t cut it.

How to limit the heap size?

I sometimes write Python programs which are very difficult to determine how much memory it will use before execution. As such, I sometimes invoke a Python program that tries to allocate massive amounts of RAM causing the kernel to heavily swap and degrade the performance of other running processes.

Python Django Global Variables

I’m looking for simple but recommended way in Django to store a variable in memory only. When Apache restarts or the Django development server restarts, the variable is reset back to 0. More specifically, I want to count how many times a particular action takes place on each model instance (database record), but for performance reasons, I don’t want to store these counts in the database. I don’t care if the counts disappear after a server restart. But as long as the server is up, I want these counts to be consistent between the Django shell and the web interface, and I want to be able to return how many times the action has taken place on each model instance.