Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betodealmeida/savepoint
An implementation of savepoints for Python, to avoid repeating expensive calculations
https://github.com/betodealmeida/savepoint
Last synced: 16 days ago
JSON representation
An implementation of savepoints for Python, to avoid repeating expensive calculations
- Host: GitHub
- URL: https://github.com/betodealmeida/savepoint
- Owner: betodealmeida
- Created: 2013-05-24T22:49:09.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-06-08T20:16:08.000Z (over 8 years ago)
- Last Synced: 2024-10-06T16:38:39.233Z (about 1 month ago)
- Language: Python
- Size: 137 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
savepoint
=========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:
```python
from savepoint import SavePointa = 10
b = 20# do some expensive calculation here
with SavePoint("stuff.p"):
print "doing stuff"
a += 10
c = 30print a, b, c
```We now run the script twice:
```bash
$ python script.py
doing stuff
20 20 30$ python script.py
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.