-
Notifications
You must be signed in to change notification settings - Fork 276
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
[WIP] Initial support for the interrupt button #460
base: main
Are you sure you want to change the base?
Conversation
Thanks @brendan0powers for starting this! |
declare global { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
interface Window { | ||
crossOriginIsolated: boolean | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we find a more canonical source for this type? or at least document where this magic variable comes from. At the very least, we'd want to move it out of the implementation, and probably in a dedicated .d.ts
somewhere...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move this to the declarations.d.ts for now. Types for crossOriginIsolated were added in typescript 4.4. microsoft/TypeScript-DOM-lib-generator#1029
I'm happy to find another way to do this as well, if you have any suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like upstream is on:
"typescript": "~4.5.2",
This would probably be separate PR, and we should have a look at what other goodies we can get any new from static analysis tooling.
if (!window.crossOriginIsolated) { | ||
console.warn( | ||
'JupyterLite is not running in a cross origin isolated context. The interrupt button will not function. Details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements' | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably use a tick-delimited string and break it up over multiple lines) so it can pass the linter... and it (along with many other constants) should probably be made internationalizable (but I wouldn't worry about it on this PR).
One approach might be to link to our some of our own, perhaps-not-yet-written documentation for this, as we can put it in a little more context.
Again, the average user is not going to open up the console to see this, so we may want to put this someplace else as well, e.g. the in-app kernel-focused log console... and potentially open it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... it's still rather a deep dive to figure out how this might be effectively set. Some ideas:
- add something to the
docs
(maybe indeploying.md
) about how one might set the appropriate headers - update serve.py to set the appropriate headers so we can evaluate something happening on e.g. binder
- probably put it behind a flag, e.g.
--enable-shared-buffer
- if this won't work over HTTP (even/especially on
localhost
), we can figure out some way to make it https with e.g.trustme
- probably put it behind a flag, e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some documentation to deployment.md, and look into adding a flag as you suggest. Logging to the log console seems like a good idea. Should the log be printed on kernel startup, or when the stop button is pressed?
@@ -412,6 +419,10 @@ self.onmessage = async (event: MessageEvent): Promise<void> => { | |||
results = commClose(messageContent); | |||
break; | |||
|
|||
case 'set-interrupt-buffer': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... i don't know if the intent of this API was to closely map to the kernel messaging spec. Ideally, there would be some way to model this on top of jupyter primitives instead of adding a new message type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty low level, and i'm not sure it's well suited for the comms API. Especially since I'm not sure what would happen if you passed a SharedArrayBuffer to python and back. I can certainly test that though, if you think we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, there are some limits to what will work (and across what boundaries, see #463) and not everything is going to map perfectly, but as the first "custom" message on this pipe, it's worth taking a look. If we could use these buffers directly, that might be great for e.g. #195.
Perhaps we need to further differentiate the types of messages... it would be lovely for us to be able to: first distinguish between:
- "well-known" kernel message types from JupyterLab
- ... and be able to use more typescript types from upstream, and maybe (ab)use totality checks in the
switch
- ... and be able to use more typescript types from upstream, and maybe (ab)use totality checks in the
- "custom" jupyterlite ones
- there might be a class of ones that all lite kernels might need, e.g. what is the root of the lite site
- per-kernel ones...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where to go from here. Do you have any concrete suggestions on an approach?
@bollwyvl Do you have any thoughts on how we could make the CORS errors more visible to the user? My preferred approach would be to gray out the stop button, remove it entirely, or show a dialog. Putting the error message in the kernel log would be better than the browser console, but I'm still not sure users would notice it. Also, I'm not sure how much freedom we have to alter the Jupyter UI. |
yeah, there's a whole class of issues in these deployment scenarios that are... hard to describe in user-relatable terms. As you say, the ideal is removing things that don't work...
...It may be possible... some command control surfaces (e.g. command palette, menu items) support an
ha, we basically have infinite freedom: it's just a question of how long we want to maintain something that's divergent from upstream. |
@bollwyvl I'm waiting on pyodide/pyodide#2142, but in the meantime, I'd like to push this forward. Do you have an idea of what you'd like to see in order for this PR to be merged? |
@@ -14,3 +14,12 @@ declare let _pipliteUrls: string[]; | |||
declare let _disablePyPIFallback: boolean; | |||
declare let pyodide: any; | |||
declare let loadPyodide: any; | |||
|
|||
// eslint-disable-next-line @typescript-eslint/naming-convention | |||
interface WindowOrWorkerGlobalScope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We synced the typescript version with the upstream, so you should be able to remove the extra typing.
Perhaps this will help: https://github.com/pyodide/pyodide/pull/2332/files |
ad442f9
to
58ede67
Compare
58ede67
to
232f408
Compare
If throwing an "info" is below the status bar threshold, maybe that at
start up and then a warning?
You may also want to see if anything is different with the pyodide 0.20
pr... I haven't been tracking what actually got merged before/after that
alpha.
|
It's great to see these patches making their way upstream, unfortunately, it doesn't change the way interrupts work. |
…few corner cases.
There is now a service worker available as of #655, which might enable more of this. |
References
#459
Code changes
User-facing changes
No user visible changes. The only effect should be the interrupt button working as epxected.
Backwards-incompatible changes
None
Remaining Issues