pyodide / pyodide/pyodide

Interrupt buffer in worker not working as expected when a custom stdout handler is set

Open
#5,232 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
14.8k
Forks
1k
Avg merge
20h 29m
Merged PRs (30d)
19

Description

## 🐛 Bug

When running python code using pyodide in a worker, with a custom stdout handler set, updating the interrupt buffer doesn't always stop execution immediately.

### To Reproduce

1. Have a pyodide worker with a sharedarraybuffer set as an interrupt buffer
2. Set a custom batch stdout function on the pyodide instance in the worker that posts a message on the worker
3. Run some python code that doesn't stop, such as:
```py
while 1:
print("Hello world")
```
4. Set the interruptBuffer[0] = 2
5. The worker continues to run for a while, continuing to send messages after you've set the interrupt buffer to keyboard interrupt

Repo with a minimal reproduction: https://github.com/alvesvaren/pyodide-worker-interrupt-issue

### Expected behavior

The execution stops immediately when I set the interrupt buffer to 2, and a KeyboardInterrupt error message is logged to the console.

### Environment

- Pyodide Version: 0.26.4
- Browser version: Firefox 133.0 (same issue in Chrome)
- Any other relevant information:

### Additional context

When running in chrome, it takes about the same amount of time for it to stop, but the "Cancelled worker"-message is sent when it's done printing messages up to that point, so I guess the messages might be queued or something.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.