bodysnatcher
Save objects when an exception occurs using pickle.
What it does
Bodysnatcher dumps frame locals() if a context is exitted via an exception.
with Bodysnatcher():
...
raise Exception # Will dump context locals()
However, it will not dump itself as that's probably not relevant.
[!WARNING] The
locals()table can be quite large depending in which scope you create the context.
By default, it dumps to the current working directory. That can be configured
using the path argument.
with Bodysnatcher("/tmp/"): ... # Dump objects to /tmp/ (e.g., /tmp/foo.pkl)
Example usage
Run
from collections.abc import Generator
from bodysnatcher import Bodysnatcher
def may_err() -> Generator[str, None, None]:
yield "Hello"
yield "World"
raise RuntimeError
def main() -> int:
data = []
with Bodysnatcher():
for elt in may_err():
data.append(elt)
return 0
if __name__ == "__main__":
raise SystemExit(main())
and then unpickle to recover the data. For example,
$ python -c "import pickle; print(pickle.load(open('data.pkl', 'rb')))"
['Hello', 'World']
Metadata
Release files for bodysnatcher 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bodysnatcher-0.1.1.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bodysnatcher-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / bodysnatcher-0.1.1.tar.gz
| Download URL | bodysnatcher-0.1.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4499929d5874f4616a7503d0d6e95e800f2e2130e8e9370751c022939bef211d
|
|
BLAKE2b-256 checksum How to use checksums |
73d9cbd28c46f6dea6c4bf393994af2d6837d4cc616e65216cbdf8b86a8ce32d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.2
|
Release files / bodysnatcher-0.1.1-py3-none-any.whl
| Download URL | bodysnatcher-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dcccd15202b828392792a1450ecfdc655c834162162f0f1e8042e5ca43e38342
|
|
BLAKE2b-256 checksum How to use checksums |
cbd1c940d3b1d2f22751f9171ecbb671af3c314982da289e9a5cd229b0cee032
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.2
|