File size: 730 Bytes
9c37cfa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | from pathlib import Path
import cloudpickle
import dill
ROOT = Path(__file__).resolve().parent
LOGS = ROOT / "logs"
LOGS.mkdir(parents=True, exist_ok=True)
marker = LOGS / "serialization_canary_loaded.txt"
cases = [
("cloudpickle", cloudpickle.load, ROOT / "canary_cloudpickle.pkl"),
("dill", dill.load, ROOT / "canary_dill.pkl"),
]
for name, loader, path in cases:
marker.unlink(missing_ok=True)
print(f"===== CONTROLLED LOAD: {name} =====")
print(f"file={path}")
print(f"exists_before={marker.exists()}")
with path.open("rb") as f:
loader(f)
print(f"exists_after={marker.exists()}")
if marker.exists():
print(f"marker_content={marker.read_text().strip()}")
print()
|