CPython on the Web

Gerry Reno greno at verizon.net
Sun Jan 2 16:01:53 EST 2011


On 01/02/2011 02:26 AM, azakai wrote:
> Hello, I hope this will be interesting to people here: CPython running
> on the web,
>
> http://syntensity.com/static/python.html
>
> That isn't a new implementation of Python, but rather CPython 2.7.1,
> compiled from C to JavaScript using Emscripten and LLVM. For more
> details on the conversion process, see http://emscripten.org
>
> This is a work in progress, main issues right now are that the code
> isn't optimized (so don't expect good performance), and importing non-
> static modules doesn't work. Otherwise, though, it seems to run
> properly, in particular it runs all the examples in
> http://wiki.python.org/moin/SimplePrograms that don't rely on
> importing modules or receiving input from the user (with perhaps some
> minor formatting errors). The demo runs fine on recent versions of
> Firefox, Chrome and Safari, but has problems on IE9 and Opera
> (hopefully those will be resolved soon).
>
> The idea is that by compiling CPython itself, all the features of the
> language are immediately present, and at the latest version, unlike
> writing a new implementation which takes time and tends to lag behind.
> As to why run it on the web, there could be various uses, for example
> it could allow a simple learning environment for Python, which since
> it's on the web can be entered immediately without any download (and
> would run even in places where Python normally can't, like say an
> iPad).
>
> Feedback would be very welcome!
>
> - azakai
>   

Ok, visiting this page:

http://syntensity.com/static/python.html

I do not see anything happen when I click 'execute' button.  I'm running
Firefox 3.6.3.

Here is what I see both before and after clicking 'execute':
=====================================

This is CPython, the standard Python <http://www.python.org>
implementation, compiled from C to JavaScript using Emscripten
<http://emscripten.org>, running in your browser (without any plugins).

    * Most core language stuff should work, except for importing
      non-static modules (in other words, |import sys| will work, but
      other modules won't).
    * Please report bugs if you find them!
    * Tested on Firefox 4 and Chrome 10.
    * The editor is Skywriter <https://mozillalabs.com/skywriter/>.

------------------------------------------------------------------------
*Enter some Python*:
import sys print 'Hello world! This is Python {} on
{}'.format(sys.version, sys.platform) print 'Here are some numbers:',
[2*x for x in range(5)][:4]

=====================================


So what is happening is that the whole Python interpreter has been
converted to Javascript and is running the browser, is that correct?

Ok, but the usual browser 'sandbox' constraints would still apply would
they not?

And what is the build toolchain that you need if you want to convert
your modules to be importable with this "CPython on the Web"?


Regards,
Gerry






More information about the Python-list mailing list