Skip to content
An implementation of savepoints for Python, to avoid repeating expensive calculations
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A context manager that creates savepoints, avoiding recalculating expensive parts of the code. Useful if you're running a script several times while developing it.

An example:

from savepoint import SavePoint

a = 10
b = 20

# do some expensive calculation here
with SavePoint("stuff.p"):
    print "doing stuff"
    a += 10
    c = 30

print a, b, c

We now run the script twice:

$ python
doing stuff
20 20 30

$ python
20 20 30

The first time the code is ran the with block is executed, and the modifed scope is pickled to stuff.p. Subsequent runs will update the global scope from the pickle file, and skip the block completely.

Note that only changes in the scope are stored, but not file modifications and other side effects of the block. Also, if the original input is different the code will fail; this will be fixed in the future, so that the savepoint is only used if the initial scope is unchanged.

You can’t perform that action at this time.