pyodide: Prompt of `input(prompt="..")` is not shown in the browser input dialog
Expected behaviour
Browser input prompt with message provided in input(prompt="..") is shown.
Actual behaviour
Prompt with message “Input” appears, instead of prompt value.
Versions Firefox 79.0 pyodide 0.15.0
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 3
- Comments: 15 (10 by maintainers)
Managed to fix this behavior by adding this code:
By the way, I have a demo with a synchronous IO implementation here. I think input, pdb, etc work with it. https://spectralsequences.com/worker-pyodide-console/ Repo: https://github.com/hoodmane/worker-pyodide-console/
This worked great. Shouldn’t this functionality be the default for Pyodide? At least after calling
pyodide.setStdin(). I was surprised I had to do this workaround as a JavaScript pop-uppromptwithout a message is pretty useless.I mentioned this on Gitter, but I suppose noting it down here would be useful. I took a stab at this, including synchronous I/O and think I figured out how to do so properly
First I edited
pyodide.jsto support redirecting stdin. While I was at it, I also decided to support redirecting the print and printErr functionshttps://github.com/stefnotch/starboard-python/blob/20c76fb95a97a3065308ccf99828efedc5badf7d/src/pyodide/pyodide.ts#L49-L60
With that set up, I could now write my own stdin. Ignoring the synchronous IO part, it would look like this
https://github.com/stefnotch/starboard-python/blob/20c76fb95a97a3065308ccf99828efedc5badf7d/src/worker/pyodide-worker.ts#L237-L253
The
intArrayFromStringis copied from emscripten, because it’s not exposed by default.I think it would be really useful to expose the input functionality, preferably with the whole wrapping and converting already being done. So, maybe something like this
Indeed has not been fixed. Hopefully we’ll add support for synchronous IO in v0.18.