5 ms·
Would it be possible to use Python directly in say Chrome, assuming someone pushed a PR for chromium to do this?
by 999900000999 5y ago
Would it be possible to use Python directly in say Chrome, assuming someone pushed a PR for chromium to do this?
- leventt 5y agoThere is this: https://pyodide.org/en/stable/console.html https://pyodide.org/en/stable/console.html Not sure what you mean by python in chromium however, I assume, pyiodide may already be doing this.
- 999900000999 5y agoI want Python to be used the same way JS is used. As in a native 3.7 interrupter in Chrome
- edgyquant 5y agoI don’t see how that could be done without nerfing a lot of the power of JS. JS was bred by the web and is entirely async. Python has no concept of callbacks or promises etc. JS is perfect for frontend design because that’s what it was created from the ground up for
- 999900000999 5y agoPython would be optional here. You could still use JS while Python support catches up.
- ekimekim 5y agoPython has always had the ability to do callbacks (ie. first class functions), though admittedly it's not a common pattern and the stdlib doesn't support it for IO (also its anonymous function syntax is poor). There have been several libraries that provide the concept of a promise, but with modern python these are built into the stdlib with native async/await support, though many interfaces are still sync-only (though you can work around that with things like gevent that monkey-patch those interfaces to work with an event loop under the hood). I agree that python would be a poor fit for the kind of uses that JS in the browser usually serve, but it's really a matter of ecosystem, not core language design.
- jagger27 5y agoThe beauty of WebAssembly is that you don't need Google's permission to add support. Just send your Wasm blob to the browser and Chrome's existing Wasm runtime will just run it.
- KMag 5y agoMy knowledge is years out of date, but does WASM still require the application to request its maximum memory footprint up-front? Granted, that's what Sun/Oracle's JVM has been doing to allocate its heap from the OS for well over a decade, but I'm also not aware if WASM is able to use the equivalent of madvise() to tell the browser/OS that it's fine to unmap a region of memory and map it back zeroed-out when it's next needed.
- AkshitGarg 5y agoYep you need to specify the maximum memory amount up-front. Its defined as "webassembly memory pages". Each page is 64kb. You need to specify an initial and a maximum amount. The webassembly module can call memory.grow() to grow it by a page until it reaches the maximum. Though you can't "un-grow" or decrease the amount of allocated memory.
- daniellehmann 5y agoThis is not correct, it is not necessary to specify a maximum memory size. See the WebAssembly specification https://webassembly.github.io/spec/core/syntax/modules.html#memories https://webassembly.github.io/spec/core/syntax/modules.html#.... Due to 32-bit address space, the maximum memory is limited to 4GB however. (In asm.js, memory was provided by an ArrayBuffer of fixed size, so there memory could truly not grow at runtime.)
- onion2k 5y agoYou'd need a pretty solid reason to want users to download the Python engine to run your code in their browser every time they visit an updated version of your site though. "I like writing Python better than JS" would be a sucky excuse. If anyone does choose to do this I hope they spend significant amount of effort making their caching and code splitting optimal.
- mirekrusin 5y agoThey did wasm to not do it and have it at the same time. What they can do is to provide GC to unbloat a lot of those runtimes I guess.
- a-dub 5y agoi don't know the story under wasm, but i looked into what it would take to embed python into a browser years ago. the hard part at the time was obviously all the hooks between the dom and the javascript runtime as well as concurrency story. python 2 was not built to be driven by callbacks, which is how the whole browser/javascript ecosystem works.