-
Notifications
You must be signed in to change notification settings - Fork 28
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
Use coincident
if crossOriginIsolated
, comlink
otherwise
#126
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b6a641
Switch from `postMessage` to `coincident`
jtpio 72a1b8a
Use `coincident` in `crossOriginIsolated`, `comlink` otherwise
jtpio ac69500
fix filesystem API setup
jtpio 9044de9
cleanup
jtpio 8f52daa
more cleanups
jtpio 6a65772
comments
jtpio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
/** | ||
* A WebWorker entrypoint that uses comlink to handle postMessage details | ||
*/ | ||
|
||
import { expose } from 'comlink'; | ||
|
||
import { ContentsAPI, DriveFS, ServiceWorkerContentsAPI } from '@jupyterlite/contents'; | ||
|
||
import { IPyodideWorkerKernel } from './tokens'; | ||
|
||
import { PyodideRemoteKernel } from './worker'; | ||
|
||
/** | ||
* A custom drive implementation which uses the service worker | ||
*/ | ||
class PyodideDriveFS extends DriveFS { | ||
createAPI(options: DriveFS.IOptions): ContentsAPI { | ||
return new ServiceWorkerContentsAPI( | ||
options.baseUrl, | ||
options.driveName, | ||
options.mountpoint, | ||
options.FS, | ||
options.ERRNO_CODES, | ||
); | ||
} | ||
} | ||
|
||
export class PyodideComlinkKernel extends PyodideRemoteKernel { | ||
/** | ||
* Setup custom Emscripten FileSystem | ||
*/ | ||
protected async initFilesystem( | ||
options: IPyodideWorkerKernel.IOptions, | ||
): Promise<void> { | ||
if (options.mountDrive) { | ||
const mountpoint = '/drive'; | ||
const { FS, PATH, ERRNO_CODES } = this._pyodide; | ||
const { baseUrl } = options; | ||
|
||
const driveFS = new PyodideDriveFS({ | ||
FS, | ||
PATH, | ||
ERRNO_CODES, | ||
baseUrl, | ||
driveName: this._driveName, | ||
mountpoint, | ||
}); | ||
FS.mkdir(mountpoint); | ||
FS.mount(driveFS, {}, mountpoint); | ||
FS.chdir(mountpoint); | ||
this._driveFS = driveFS; | ||
} | ||
} | ||
} | ||
|
||
const worker = new PyodideComlinkKernel(); | ||
|
||
expose(worker); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 could technically keep both entrypoints in a single file. But having a separate file for
coincident
andcomlink
may be easier to reason about.