From 2f1c625df4e5a3688639a3b82bb95bcbedc5b3c7 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 27 Mar 2024 22:12:45 +0100 Subject: [PATCH] Python baseline snapshot: Invalidate caches Invalidate caches if we have a baseline snapshot because the contents of site-packages may be different when we rerun. --- src/pyodide/internal/python.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pyodide/internal/python.js b/src/pyodide/internal/python.js index 5bbfd3c7880..9759d356ca1 100644 --- a/src/pyodide/internal/python.js +++ b/src/pyodide/internal/python.js @@ -553,6 +553,11 @@ export async function loadPyodide(lockfile, indexURL) { // Finish setting up Pyodide's ffi so we can use the nice Python interface await enterJaegerSpan("finalize_bootstrap", Module.API.finalizeBootstrap); const pyodide = Module.API.public_api; + if (DSO_METADATA?.settings?.baselineSnapshot) { + // Invalidate caches if we have a baseline snapshot because the contents of site-packages may + // have changed. + simpleRunPython(Module, "from importlib import invalidate_caches as f; f(); del f"); + } // This is just here for our test suite. Ugly but just about the only way to test this. if (TEST_SNAPSHOT) {