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

Add setInterruptBuffer to public API, update changelog and docs #1173

Merged
merged 10 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/project/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
of Pyodide REPL in webpages (used in console.html) [#1125](https://github.com/iodide-project/pyodide/pull/1125) and [#1155](https://github.com/iodide-project/pyodide/pull/1155)
- Flexible jsimports: it now possible to add custom Python "packages" backed by Javascript code, like the js package.
The js package is now implemented using this system. [#1146](https://github.com/iodide-project/pyodide/pull/1146)
- Added the `pyodide.setInterruptBuffer` API. This can be used to set a `SharedArrayBuffer` to be the keyboard interupt buffer. If Pyodide is running on a webworker, the main thread can signal to the webworker that it should raise a `KeyboardInterrupt` by writing to the interrupt buffer.
hoodmane marked this conversation as resolved.
Show resolved Hide resolved

### Fixed
- getattr and dir on JsProxy now report consistent results and include all names defined on the Python dictionary backing JsProxy. [#1017](https://github.com/iodide-project/pyodide/pull/1017)
Expand Down
1 change: 1 addition & 0 deletions docs/usage/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Backward compatibility of the API is not guaranteed at this point.
| **{ref}`js_api_pyodide_runPython`** | Runs Python code from Javascript. |
| **{ref}`pyodide.runPythonAsync(code, ...) <js_api_pyodide_runPythonAsync>`** | Runs Python code with automatic preloading of imports. |
| **{ref}`js_api_pyodide_version`** | The pyodide version string. |
| **{ref}`pyodide.setInterruptBuffer(interruptBuffer) <js_api_pyodide_setInterruptBuffer>`** | Set the keyboard interrupt buffer |


```{eval-rst}
Expand Down
12 changes: 12 additions & 0 deletions docs/usage/js-api/pyodide.setInterruptBuffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(js_api_pyodide_setInterruptBuffer)=
# pyodide.setInterruptBuffer(interruptBuffer)
This is a low level API for handling keyboard interrupts.
Sets the pyodide interrupt buffer to be `interruptBuffer`. If thereafter one sets `interruptBuffer[0] = 2;` (2 stands for SIGINT) this will cause Pyodide to raise a `KeyboardInterupt`. The value of `interruptBuffer[0]` will regularly be set back to zero.
This is intended for use when Pyodide is running on a webworker. In this case, one should make `interruptBuffer` a `SharedArrayBuffer` shared with the main thread. If the user requests a keyboard interrupt from the main thread, then the main thread can set `interruptBuffer[0] = 2;` and this will signal the webworker to raise a KeyboardInterupt exception.
hoodmane marked this conversation as resolved.
Show resolved Hide resolved


**Parameters**

| name | type | description |
|--------------------|------------|------------------------------------------------------|
| *interruptBuffer* | TypedArray | The SharedArrayBuffer to use as the interrupt buffer |
1 change: 1 addition & 0 deletions src/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ globalThis.languagePluginLoader = new Promise((resolve, reject) => {
'version',
'registerJsModule',
'unregisterJsModule',
'setInterruptBuffer',
];

function makePublicAPI(module, public_api) {
Expand Down