The assumption a restore would break
If a Python process were to begin “restoring from a memory snapshot”, effectively this is what would happen for hash seed randomization: a value that is expected to be randomized every time would become deterministic and shared across all snapshots. [1]
Hood noted that there were likely other places, especially in libraries and programs, where this assumption would break existing use-cases, too. [2]
The proposed initialization phase
Hood proposed that the concept of an “initialization phase” be added to the Python language model, citing RPython and SPy as two runtimes that have introduced an “explicit entrypoint to an initialization phase”. [3]
This initialization phase could be called again on re-initialization, allowing the runtime and third-party libraries to safely reintroduce randomness into the program if memory snapshotting were implemented. [4]
Stefan Behnel referenced some similar functionality that Python already provides: the atexit module, which provides an API for registering a callback function that is called when the Python process is exiting. [5]
Stefan wondered whether a reinit callback function could serve the needs Hood described. [6]
Lazy imports and snapshots
Thomas Wouters wondered whether lazy imports, defined in PEP 810 and coming to Python 3.15, would solve some of the issues with slow initialization. [7]
Hood was cautious, stating that lazy imports might make his specific use-case “worse before it gets better”, especially if memory snapshots were implemented for Python. [8]
Snapshots, however, benefit performance because the cost to parse and execute all imports is paid a single time, the state is saved, and then it is “restored” in future executions to skip this part of the process. [9]
If imports aren’t resolved initially (such as when lazy imports are used), then the imports won’t be saved in the snapshot, and their cost will be paid on each Python execution, even if memory snapshots are implemented. [10]
Sources
- The Python Software Foundation source says: If a Python process were to begin “restoring from a memory snapshot”, effectively this is what would happen for hash seed randomization: a value that is expected to be randomized every time would become deterministic and shared across all snapshots. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Hood noted that there were likely other places, especially in libraries and programs, where this assumption would break existing use-cases, too. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Hood proposed that the concept of an “initialization phase” be added to the Python language model, citing RPython and SPy as two runtimes that have introduced an “explicit entrypoint to an initialization phase”. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: This initialization phase could be called again on re-initialization, allowing the runtime and third-party libraries to safely reintroduce randomness into the program if memory snapshotting were implemented. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Stefan Behnel referenced some similar functionality that Python already provides: the atexit module, which provides an API for registering a callback function that is called when the Python process is exiting. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Stefan wondered whether a reinit callback function could serve the needs Hood described. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Thomas Wouters wondered whether lazy imports, defined in PEP 810 and coming to Python 3.15, would solve some of the issues with slow initialization. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Hood was cautious, stating that lazy imports might make his specific use-case “worse before it gets better”, especially if memory snapshots were implemented for Python. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: Snapshots, however, benefit performance because the cost to parse and execute all imports is paid a single time, the state is saved, and then it is “restored” in future executions to skip this part of the process. Memory Snapshots for CPython (Python Language Summit 2026)
- The Python Software Foundation source says: If imports aren’t resolved initially (such as when lazy imports are used), then the imports won’t be saved in the snapshot, and their cost will be paid on each Python execution, even if memory snapshots are implemented. Memory Snapshots for CPython (Python Language Summit 2026)