Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Workers w/out SharedArrayBuffer #1967

Merged
merged 2 commits into from Feb 2, 2024

Conversation

WebReflection
Copy link
Contributor

@WebReflection WebReflection commented Feb 2, 2024

Description

This MR is a follow up integration of pyscript/polyscript#80

Beside fixing the exported JS' PyWorker, which was fully broken and not smoke-tested properly, these changes allow the usage of PyScript in workers without DOM primitives or mechanism that requires synchroonus worker -> main operations, still allowing the worker code to expose, via pyscript.sync, any utility / callback that can be then consumed via the main thread only asynchronously.

Example

<!-- main thread -->
<script type="module">
import { PyWorker } from '@pyscript/core';

const { sync } = await PyWorker(
  './worker.py',
  { config: { sync_main_only: true } }
);

console.log(await sync.utility(3));
// log: 6
</script>
# worker.py
from pyscript import sync

def utility(num):
  # some complex operation
  return num * 2

sync.utility = utility

This MR takes the opportunity to also expose MPWorker beside PyWorker as that was also missing before.

Changes

  • breaking (but then again, it was already broken): the PyWorker in the JS side of affairs returns a promise which is resolved when the worker has fully bootstrapped, guaranteeing that sync utilities can be accessed later on
  • new: it is now possible to use sync_main_only configuration flag to disable any DOM in workers but still allow the main thread to interact with their exported pyscript.sync utilities
  • added a smoke test that cannot be tested with the rest of the tests because the server must bootstrap without any special header
  • simplified even more the worker initialization (compared to its primitive polyscript counter part) by awaiting out of the box the lately introduced ready promise for XWorker

Checklist

  • All tests pass locally
  • I have updated CHANGELOG.md
  • I have created documentation for this(if applicable)

Copy link
Member

@ntoll ntoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@WebReflection WebReflection merged commit 181d276 into pyscript:main Feb 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants