{"id":20600988,"url":"https://github.com/spectralsequences/pyodide_interrupts","last_synced_at":"2026-04-17T23:03:08.849Z","repository":{"id":62582197,"uuid":"320933238","full_name":"SpectralSequences/pyodide_interrupts","owner":"SpectralSequences","description":"Python extension package to do interrupt handling for pyodide","archived":false,"fork":false,"pushed_at":"2020-12-13T08:05:03.000Z","size":6,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-30T14:54:03.043Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpectralSequences.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-12T22:04:16.000Z","updated_at":"2020-12-13T08:05:05.000Z","dependencies_parsed_at":"2022-11-03T21:21:59.890Z","dependency_job_id":null,"html_url":"https://github.com/SpectralSequences/pyodide_interrupts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SpectralSequences/pyodide_interrupts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpectralSequences%2Fpyodide_interrupts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpectralSequences%2Fpyodide_interrupts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpectralSequences%2Fpyodide_interrupts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpectralSequences%2Fpyodide_interrupts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpectralSequences","download_url":"https://codeload.github.com/SpectralSequences/pyodide_interrupts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpectralSequences%2Fpyodide_interrupts/sbom","scorecard":{"id":132809,"data":{"date":"2025-08-04","repo":{"name":"github.com/SpectralSequences/pyodide_interrupts","commit":"0dfd2d5a286bce095dc70d3f9ffc87494ebd1869"},"scorecard":{"version":"v5.2.1-28-gc1d103a9","commit":"c1d103a9bb9f635ec7260bf9aa0699466fa4be0e"},"score":2.8,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/3 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":8,"reason":"binaries present in source code","details":["Warn: binary detected: pyodide_interrupts/__pycache__/__init__.cpython-36.pyc:1","Warn: binary detected: pyodide_interrupts/__pycache__/__init__.cpython-38.pyc:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T05:36:31.359Z","repository_id":62582197,"created_at":"2025-08-16T05:36:31.359Z","updated_at":"2025-08-16T05:36:31.359Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31949435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T09:08:03.748Z","updated_at":"2026-04-17T23:03:08.807Z","avatar_url":"https://github.com/SpectralSequences.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyodide_interrupts\r\nThis is a package to allow handling of interrupts inside of Pyodide. \r\nPyodide does not have preemptive multitasking. This package enables handling keyboard interrupts in Pyodide.\r\n\r\nThis defines one context handler `check_interrupts(callback, interval)` which causes `callback` to be called every `interval` instructions.\r\n\r\n## Simple Example:\r\n```python\r\n\u003e\u003e\u003e def callback(): print(\"check\")\r\n... with check_interrupts(callback, 10):\r\n...    for i in range(50):\r\n...       print(i, end=\",\")\r\n\r\n0,1,check\r\n2,3,4,5,6,check\r\n7,8,9,10,11,check\r\n12,13,14,15,16,check\r\n17,18,19,20,21,check\r\n22,23,24,25,26,check\r\n27,28,29,30,31,check\r\n32,33,34,35,36,check\r\n37,38,39,40,41,check\r\n42,43,44,45,46,check\r\n47,48,49,check\r\n```\r\n\r\n## Sketch of usage\r\n\r\nIn real usage, I use the following callback:\r\n```python\r\ndef check_for_interrupt(interrupt_buffer):\r\n    def helper():\r\n        if interrupt_buffer() == 0:\r\n            return\r\n        raise KeyboardInterrupt()\r\n    return helper\r\n```\r\n\r\n`interrupt_buffer` is a javascript wrapper around a `SharedArrayBuffer`. On the main thread:\r\n```javascript\r\nlet uuid = uuid();\r\nlet interrupt_buffer = new Int32Array(new SharedArrayBuffer(4));\r\npyodide_worker.postMessage({\"cmd\" : \"execute_python\", code, interrupt_buffer, uuid});\r\nlet result = await responsePromise(uuid);\r\n// If user cancels, write a nonzero value into our SAB, this will signal pyodide to quit execution of code.\r\nonUserCancel(() =\u003e { interrupt_buffer[0] = 2; });\r\n```\r\nOn the pyodide worker thread:\r\n```javascript\r\nself.messages = {};\r\nfunction handleExecutePython(msg){\r\n    // Wrap interrupt buffer in a function that gets its value\r\n    // Pyodide Python \u003c==\u003e Javascript bindings don't understand how to get values out of the SAB directly.\r\n    msg.interrupt_buffer = function(){\r\n        return msg.interrupt_buffer[0]; \r\n    };\r\n    messages[msg.uuid] = msg;\r\n    self.pyodide.globals[\"handle_message\"](uuid);\r\n}\r\n```\r\nand then the pyodide code:\r\n\r\n```python\r\nfrom js import messages, postMessage\r\ndef handle_message(uuid):\r\n    msg = dict(messages[uuid])\r\n    del messages[uuid]\r\n    # Here would use msg[\"cmd\"] to look up handling in a dispatch.\r\n    interrupt_buffer = msg[\"interrupt_buffer\"]\r\n    # check_for_interrupt will raise a KeyboardInterrupt if \"onUserCancel\" handler is executed on main thread.\r\n    with check_interrupts(check_for_interrupt(interrupt_buffer), 10_000):\r\n        result = run_code(code)\r\n    postMessage({\"cmd\" : \"execute_pyodide_result\", \"result\" : result, \"uuid\" : uuid })\r\n\r\ndef run_code(code):\r\n    # Parse code into ast, handle errors, get result out, etc here\r\n```\r\n\r\n## Security requirements for `SharedArrayBuffer` to work\r\n\r\nI quote from [the MDN docs for SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer):\r\n\r\n\u003e As a baseline requirement, your document needs to be in a secure context.\r\n\r\n\u003e For top-level documents, two headers will need to be set to cross-origin isolate your site:\r\n\r\n\u003e    Cross-Origin-Opener-Policy with same-origin as value (protects your origin from attackers)\r\n\u003e    Cross-Origin-Embedder-Policy with require-corp as value (protects victims from your origin)\r\n\r\n\u003e Cross-Origin-Opener-Policy: same-origin\r\n\u003e Cross-Origin-Embedder-Policy: require-corp\r\n\r\n\u003e To check if cross origin isolation has been successful, you can test against the crossOriginIsolated property available to window and worker contexts\r\n\r\n## Building\r\nTo build a copy for local use, I recommend creating a virtual environment and then using `pip install .` in that virtual environment.\r\nTo upload to pypi, we must build the package for a `manylinux` ABI to insure that the binaries will be compatible with most systems.\r\nThe [manylinux](https://github.com/pypa/manylinux) repository provides docker images with the appropriate old versions of CentOS for us to use to build these. To build, run `sudo ./docker_build_wheels.sh`. **Warning:** This will download a ~300mb docker image the first time you do it. Note that you will need to have docker installed for this to work.\r\nThe resulting wheels will end up in the `dist` directory and will be suitable for upload to pypi.\r\n\r\n## [0.1.0] (2020-07-25)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspectralsequences%2Fpyodide_interrupts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspectralsequences%2Fpyodide_interrupts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspectralsequences%2Fpyodide_interrupts/lists"}