mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
hack hack hack until pyterminal works also in workers
This commit is contained in:
@@ -75,9 +75,19 @@ const registerModule = ({ XWorker: $XWorker, interpreter, io }) => {
|
||||
interpreter.runPython(stdlib, { globals: interpreter.runPython("{}") });
|
||||
};
|
||||
|
||||
// this is a super-ugly workaround for a polyscript issue: in theory I should
|
||||
// define a codeBeforeRunWorker hook inside py-terminal.js, but since it's a
|
||||
// lazy plugin, it is too late: https://github.com/pyscript/polyscript/issues/52
|
||||
const py_terminal_codeBeforeRunner = `
|
||||
from pyscript import pyterminal
|
||||
pyterminal.init()
|
||||
`;
|
||||
|
||||
const workerHooks = {
|
||||
codeBeforeRunWorker: () =>
|
||||
[stdlib, ...hooks.codeBeforeRunWorker].map(dedent).join("\n"),
|
||||
[stdlib, py_terminal_codeBeforeRunner, ...hooks.codeBeforeRunWorker]
|
||||
.map(dedent)
|
||||
.join("\n"),
|
||||
codeBeforeRunWorkerAsync: () =>
|
||||
[stdlib, ...hooks.codeBeforeRunWorkerAsync].map(dedent).join("\n"),
|
||||
codeAfterRunWorker: () =>
|
||||
@@ -135,7 +145,8 @@ for (const [TYPE, interpreter] of TYPES) {
|
||||
errors.set(element, error);
|
||||
},
|
||||
...workerHooks,
|
||||
onWorkerReady(_, xworker) {
|
||||
async onWorkerReady(_, xworker) {
|
||||
await plugins; // workaround for a polyscript bug
|
||||
assign(xworker.sync, sync);
|
||||
for (const callback of hooks.onWorkerReady)
|
||||
callback(_, xworker);
|
||||
|
||||
Reference in New Issue
Block a user