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

Multiple Worker based Terminals #1948

Merged
merged 3 commits into from Jan 24, 2024

Conversation

WebReflection
Copy link
Contributor

@WebReflection WebReflection commented Jan 22, 2024

Description

As discussed with both @ntoll and @JeffersGlass, we'd love to be able to have multiple terminals on a page through worker attribute, as these are all fresh-new bootstrapped interpreters, these can be interactive too and any constraint regarding the main thread can be easily avoided / ignored.

This MR makes it possible to use 1, 2, or any amount of <script type="py" worker terminal> on the same page, being these either bootstrapped all at once or incrementally (dynamically).

Changes

  • added a shared sync.is_pyterminal() utility to understand within hooks if the xworker is actually meant to be used as terminal or it's just a regular worker. By default that returns false but bootstrapped workers will have it returning true
  • moved the worker related (and then stringified) hook in the outer scope that it won't ever be added more than once
  • removed the need to drop such hook in workers as that might lead to more problems than it solves (hooks are shared across all workers so that multiple callbacks will bootstrap workers more than once and we never want that to happen)
  • for the very same reason, initialization on main per each xworker is also guarded as only once. This is because the sync properties never need to be assigned twice and also because the terminal itself should never be bootstrapped more than once
  • added a test/py-terminals.html smoke test that is also used as integration test to live-demo that indeed we can have multiple terminals and no issue whatsoever happens when that's the case

Side Notes

  • if anything, this MR made me realize that identical hooks, even if created in different scopes, should never be added more than once (that is: a function meant to be stringified that is already present in such string representation in the hooks stack should not ever be added more than once ... I will follow up with a PR maybe here or maybe in Polyscript
  • it is very possible that integration tests might fail now because we currently can have multiple terminals ... although previous tests, IIRC, never use the worker attribute and new integration tests have been added so ... maybe we're good to go? I'll wait for CI to tell me something I have updated integration tests and I think everything should be fine now

Checklist

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

@WebReflection WebReflection force-pushed the multiple-worker-terminals branch 2 times, most recently from 2248968 to de23cf5 Compare January 24, 2024 15:51
@WebReflection WebReflection changed the title WIP Multiple Worker based Terminals Jan 24, 2024
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 f6470dc into pyscript:main Jan 24, 2024
3 checks passed
WebReflection added a commit to WebReflection/pyscript that referenced this pull request Jan 25, 2024
Multiple Worker based Terminals
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