CPython on the Web

azakai alonmozilla at gmail.com
Sun Jan 2 14:29:09 EST 2011


On Jan 2, 5:52 am, "Octavian Rasnita" <orasn... at gmail.com> wrote:
>
> Then, how can the Python programs run on the "desktop"?
> I suspect that the Python code is somehow translated to Javascript in order to run on the browser. Am I right?

To clarify, in this demo, CPython itself - the C implementation of
Python - was translated from C to JavaScript (or more specifically, C
to LLVM, and LLVM to JavaScript). So your web browser is running the
same CPython that you would run on your computer normally.

That CPython executes Python by compiling it into bytecode, etc., and
that is exactly the same with CPython normally and CPython on the web
in this demo. So actual Python code is not translated into JavaScript
(which is the approach pyjamas takes), instead the entire interpreter
is.

>
> If yes, then how can run a Python code that access a database or one that create a web server, or a WxPython GUI run?

By implementing whatever library functions and system calls CPython
needs, in the browser. For example, if the CPython code calls printf()
to print stuff, then we need to implement printf() in JavaScript, and
so forth.

Obviously there are limitations of the JS environment, so not
everything can be done.

>
> BTW. I have tried that page, and it appeared a JS error window telling that the JS scripts run too slow and it asked me if I want to continue.
> I have executed the default Python script, but nothing happend. Nothing was printed. I use Internet Explorer.
>

I've been told it doesn't run properly on IE, we have a bug open on
that, sorry. It will work on Firefox, Chrome and Safari right now.

- azakai



More information about the Python-list mailing list