From 6a1f4430c7b434129dfed77ee692fd5a8bf124be Mon Sep 17 00:00:00 2001 From: Chengxun Lee <24319042+bclswl0827@users.noreply.github.com> Date: Wed, 28 Feb 2024 01:17:50 +0800 Subject: [PATCH] Protect Pyodide runtime from being polluted --- src/helpers/getPythonResult.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/helpers/getPythonResult.tsx b/src/helpers/getPythonResult.tsx index d52831f..9c9a94a 100644 --- a/src/helpers/getPythonResult.tsx +++ b/src/helpers/getPythonResult.tsx @@ -43,7 +43,11 @@ export const getPythonResult = async ( messageCallback: (x) => onImporting(x, false), }); } - await pyodide.runPythonAsync(code); + const dict = pyodide.globals.get("dict"); + const globals = dict(); + await pyodide.runPythonAsync(code, { globals, locals: globals }); + globals.destroy(); + dict.destroy(); } catch (e) { let err = String(e); if (err.endsWith("\n")) {