mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 10:17:23 -05:00
[next] xworker.sync pollution example (#1659)
This commit is contained in:
committed by
GitHub
parent
4cc9647dc6
commit
da3b43abdd
File diff suppressed because one or more lines are too long
@@ -2,6 +2,7 @@ import "@ungap/with-resolvers";
|
||||
import { $ } from "basic-devtools";
|
||||
import { define, XWorker } from "polyscript";
|
||||
import { htmlDecode } from "./utils.js";
|
||||
import sync from "./sync.js";
|
||||
|
||||
// this is imported as string (via rollup)
|
||||
import display from "./display.py";
|
||||
@@ -179,6 +180,9 @@ define("py", {
|
||||
env: "py-script",
|
||||
interpreter: "pyodide",
|
||||
...workerHooks,
|
||||
onWorkerReady(_, xworker) {
|
||||
assign(xworker.sync, sync);
|
||||
},
|
||||
onBeforeRun(pyodide, element) {
|
||||
currentElement = element;
|
||||
bootstrapNodeAndPlugins(pyodide, element, before, "onBeforeRun");
|
||||
@@ -269,8 +273,10 @@ export function PyWorker(file, options) {
|
||||
// as the interpreter to use in the worker, as all hooks assume that
|
||||
// and as `pyodide` is the only default interpreter that can deal with
|
||||
// all the features we need to deliver pyscript out there.
|
||||
return XWorker.call(new Hook(null, workerHooks), file, {
|
||||
const xworker = XWorker.call(new Hook(null, workerHooks), file, {
|
||||
...options,
|
||||
type: "pyodide",
|
||||
});
|
||||
assign(xworker.sync, sync);
|
||||
return xworker;
|
||||
}
|
||||
|
||||
5
pyscript.core/src/sync.js
Normal file
5
pyscript.core/src/sync.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default {
|
||||
sleep(seconds) {
|
||||
return new Promise(($) => setTimeout($, seconds * 1000));
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,9 @@
|
||||
from pyscript import display
|
||||
from pyscript import display, sync
|
||||
|
||||
import a
|
||||
|
||||
display("Hello World", target="test", append=True)
|
||||
|
||||
print("sleeping")
|
||||
sync.sleep(1)
|
||||
print("awake")
|
||||
|
||||
1
pyscript.core/types/core.d.ts
vendored
1
pyscript.core/types/core.d.ts
vendored
@@ -22,4 +22,5 @@ export namespace hooks {
|
||||
let codeAfterRunWorkerAsync: Set<string>;
|
||||
}
|
||||
declare let config: any;
|
||||
import sync from "./sync.js";
|
||||
export {};
|
||||
|
||||
4
pyscript.core/types/sync.d.ts
vendored
Normal file
4
pyscript.core/types/sync.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare namespace _default {
|
||||
function sleep(seconds: any): Promise<any>;
|
||||
}
|
||||
export default _default;
|
||||
Reference in New Issue
Block a user