mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 12:05:39 -05:00
fix: reuse python worker between tests (#52617)
This commit is contained in:
committed by
GitHub
parent
0cb5162e21
commit
06bbc07ec6
@@ -135,8 +135,8 @@ function initRunPython() {
|
||||
return ""
|
||||
`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
const getResetId = globals.get('__get_reset_id') as () => string;
|
||||
return { runPython, getResetId };
|
||||
const getResetId = globals.get('__get_reset_id') as PyProxy & (() => string);
|
||||
return { runPython, getResetId, globals };
|
||||
}
|
||||
|
||||
ctx.onmessage = (e: PythonRunEvent | ListenRequestEvent | CancelEvent) => {
|
||||
@@ -165,7 +165,7 @@ function handleRunRequest(data: PythonRunEvent['data']) {
|
||||
// TODO: use reset-terminal for clarity?
|
||||
postMessage({ type: 'reset' });
|
||||
|
||||
const { runPython, getResetId } = initRunPython();
|
||||
const { runPython, getResetId, globals } = initRunPython();
|
||||
// use pyodide.runPythonAsync if we want top-level await
|
||||
try {
|
||||
runPython(code);
|
||||
@@ -184,5 +184,8 @@ function handleRunRequest(data: PythonRunEvent['data']) {
|
||||
// ...and tell the client that we're ignoring them.
|
||||
postMessage({ type: 'stopped', text: getResetId() });
|
||||
}
|
||||
} finally {
|
||||
getResetId.destroy();
|
||||
globals.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user