treyhunner,
@treyhunner@mastodon.social avatar

The Python Morsels REPL (https://pym.dev/repl) now properly supports using Ctrl+D to stop standard input! A user recently tested out code that relied on sys.stdin.read() and ended up stuck without a way to send EOF.

Thanks @notsolonecoder for a 1.5 year old unmerged CPython PR that contained the keys to fixing this issue!

https://github.com/python/cpython/pull/97665

notsolonecoder,
@notsolonecoder@aus.social avatar

@treyhunner oh wow! Glad it was useful!

notsolonecoder,
@notsolonecoder@aus.social avatar

@treyhunner most of the stuff is just making a terminal that works ok when Python doesn't have readline support.

Wonder if it'd be helpful to make a library that wraps xterm.js in a nice box and can run arbitrary CLI processes in a webworker?

treyhunner,
@treyhunner@mastodon.social avatar

@notsolonecoder I think it would be!

I've also thought of trying to at least make a better demo for folks that lives outside of CPython's repo. I'd be happy to collaborate on and/or beta test either/both of these things.

Completely separately: support for WebAssembly support for readline and curses one day would be incredible. Both are required for the brand new Python REPL in CPython's main branch, which I'm pretty sure means no new-style REPL in WASM land. This seems far less trivial though.

pg,
@pg@hci.social avatar

@treyhunner @notsolonecoder nice! is this all in-browser, like using pyodide or something similar?

treyhunner,
@treyhunner@mastodon.social avatar

@pg @notsolonecoder yes it's fully in-browser, running on CPython compiled to WebAssembly via Emscripten.

The Python Morsels exercise automated tester is powered by this as well, so user solutions run right in the browser.

Also this pastebin tool runs on the same system: https://pym.dev/p

I'm not using pyodide because I don't want to allow arbitrary JS code execution. A pyodide dev told me that I could have put a wrapper/sandbox around pyodide to accomplish something similar as well.

pg,
@pg@hci.social avatar

@treyhunner @notsolonecoder ah nice didn't realize there was an official (?) cpython build for webassembly, seems more lightweight than full-on pyodide

pg,
@pg@hci.social avatar

@treyhunner @notsolonecoder my main concern with wasm stuff for python is long initial load times for first-time users -- the smallest pyodide packages i found back in the day were maybe ~10MB, which isn't huge but takes a few seconds for slower connections. if the package is only ~1MB then that could be very compelling. pandas tutor uses pyodide but has a few seconds of load time: https://pandastutor.com/

treyhunner,
@treyhunner@mastodon.social avatar

@pg Yup! @notsolonecoder has given a number of talks on WebAssembly and CPython: https://www.youtube.com/results?search_query=katie+bell+webassembly

I understand the concern of load time. Since the running on Python Morsels is triggered by the user, the wasm file is often loaded by the time the user hits the run button and when it's not it typically only adds a couple seconds delay.

I'm hoping smart folks find a way to make the initial wasm file that's sent considerably smaller.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • khanakhh
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • cubers
  • GTA5RPClips
  • cisconetworking
  • ethstaker
  • osvaldo12
  • modclub
  • normalnudes
  • provamag3
  • tester
  • anitta
  • Leos
  • megavids
  • lostlight
  • All magazines