Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/toml-V4Savzlc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/toml-V4Savzlc.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions esm/worker/_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
if (list.length) {
interpreter.runPython([
`from ${polyscript} import xworker as ${workers}`,
`${workers}.sync.__export__ = lambda:${JSON.stringify(list)}`,
...list.map(util => `${workers}.sync.${util} = ${util}`),
`del ${workers}`,
].join('\n'));
Expand Down
9 changes: 8 additions & 1 deletion esm/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ export const workers = new Proxy(new Map, {
// @issue https://github.com/pyscript/pyscript/issues/2106
const ignore = new Set(['__dict__', 'constructor', 'get', 'has', 'includes', 'next', 'set', 'then']);

const exportHandler = {
get: (target, prop) => {
const method = target[prop];
return prop === '__export__' ? method() : method;
}
};

export const workersHandler = new Proxy(Object.freeze({}), {
// guard against forever pending Promises in Pyodide
// @issue https://github.com/pyscript/pyscript/issues/2106
get: (_, name) => (typeof name === 'string' && !ignore.has(name)) ?
workers[name].promise.then(w => w.sync) :
workers[name].promise.then(w => new Proxy(w.sync, exportHandler)) :
void 0,
});
/* c8 ignore stop */
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@
"to-json-callback": "^0.1.1"
},
"worker": {
"blob": "sha256-ApE1J3NhEObM1H24FVV9LhqLlLGKcfe+iUy+8s/CKJE="
"blob": "sha256-GAb/WDsbp8Z85OBm+d3VtcOBoZ2mlbuzQKJsre1kTAs="
}
}
13 changes: 11 additions & 2 deletions test/worker/named.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@

await (await workers["mpy"]).greetings()
await (await workers["py"]).greetings()

# print(await (await workers["mpy"]).__export__)
print(list(await (await workers["mpy"]).test()))
</script>
<script type="micropython" worker name="mpy">
def greetings():
print("micropython")

__export__ = ['greetings']
def test():
return __export__

__export__ = ['greetings', 'test']
</script>
<script type="pyodide" worker name="py">
def greetings():
print("pyodide")

__export__ = ['greetings']
def test():
return __export__

__export__ = ['greetings', 'test']
</script>
</body>
</html>