Thonny on the web?

1,389 views
Skip to first unread message

Kenneth C. Arnold

unread,
Jul 20, 2022, 5:44:59 PM7/20/22
to thonny
An early-stage idea, just wondering if anyone else has thought about this:

The web platform is a great place to run code: images, video, speech recognition, peer-to-peer communication, and many more things are built-in features. Beyond that, there are lots of great libraries (tensorflow.js, Observable Plot, ). And with some infrastructure, the results can be shared with friends who don't need to install anything.

In the past, coding for the web has required coding in JavaScript or related languages, but Pyodide runs the real CPython interpreter. Even things like scikit-learn work.

If there were a way to run Pyodide as a Thonny backend, that could provide a way for students to develop code that runs in-browser. (Sharing that code so it runs on anything but your own computer could be a nice-to-have; local-only would already be a big win.)

One way of doing this would be to have Thonny spin up a tiny webserver to host the code and set up a bidirectional channel (Websockets or similar) to a web page that imports Pyodide and runs code on demand. Ability to interrupt code and debug would probably require using a WebWorker and some extra machinery; https://github.com/pyodide/pyodide/issues/550 has some directions to explore, and https://futurecoder.io/ could be considered a proof of concept.

Another way of doing this would be to implement enough of Tkinter on top of the DOM so that Thonny itself could run in-browser. (possibly relying on an existing code editor widget like CodeMirror, and maybe some other variations where mimicking Tkinter exactly would be troublesome.) Then it could probably use the existing backend code mostly unchanged.

This would clearly be a big project, but... thoughts?


PS - Brython and Skulpt (used by Runestone iirc) are also options. They transpile to JavaScript, so the result would be faster and lighter-weight than Pyodide. Brython is particularly impressive in its scope. But even so, there are various differences from CPython. They are mostly small, like random.seed() not working.

Aivar Annamaa

unread,
Jul 21, 2022, 3:46:39 PM7/21/22
to thonny
These are interesting ideas, but as I already have a large TODO list I don't see myself doing any of this. I like the idea of effortless sharing of one's code (which would align nicely with Thonny's educational goals), but this is not trivial to implement even if the right technology is set up. Therefore I intend to keep Thonny focused on desktop and microcontrollers. (The latter has already blurred the focus considerably and now takes most of my Thonny time, but it's too late to back out.)

If I had more time, I would create a separate project for writing and executing Python on the web, which focused on some kind of visual output, sharing and remixing -- something like scratch.mit.edu. Skulpt would be totally good for such a thing. But this project would have different goals compared to Thonny and I wouldn't see the value in relating it to Thonny in any way.

When I was teaching, I valued solutions which made the learning process smoother for the student and myself. For an example -- that's why I started publishing Thonny+Python bundles. I still see the value in this, but after having worked in the industry for some years, I feel that the university does not do much to prepare the student for the messiness of the real jobs. I now think that besides developing the computational thinking, the university (and maybe even lower level schools) should also develop students' ability to tinker and debug in wilder environments -- mixing and matching different technologies and finding their way out of such contraptions. I know that most CS teachers don't like making students to deal with dirty technological issues like installing programs (and -- I'm told -- even managing files). They say it would make their lessons slower and less predictable, and would waste the time meant for the real thing. I now think that teaching someone to combine two different programs (command line or GUI or web) and change some OS settings on the way to achieve a goal is worth more than teaching them if-else-while in a sterile setting. Doesn't matter if the student finally ends up as a programmer or a clerk.

That's why I now have less urge to add new convenience features to Thonny. Or maybe I'm just trying to cope with my regret of not having enough time for Thonny :D

Best regards,
Aivar

Reply all
Reply to author
Forward
0 new messages