Re: CPython on the Web
On Jan 3, 10:11 pm, John Nagle wrote: > On 1/1/2011 11:26 PM, 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, seehttp://emscripten.org > > It's a cute hack, but it's about 1000 times slower than CPython. > > Try > > def cnt(n) : > j = 0 > for i in xrange(n) : > j = j + 1 > return(j) > > print(cnt(100)) > > with this. It will take 30 seconds or so to count to a million. > > John Nagle Yes, as I said, "the code isn't optimized (so don't expect good performance)" :) It can get much faster with more work. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 3, 12:23 pm, Gerry Reno wrote: > On 01/03/2011 03:10 PM, azakai wrote: > > > > > > > > > > > On Jan 2, 5:55 pm, Gerry Reno wrote: > > >> I tried printing sys.path and here is the output: > > >> ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/', > >> '/usr/local/lib/python2.7/plat-linux2', > >> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', > >> '/usr/local/lib/lib-dynload'] > > >> Now, those paths must be on your machine because they are not on my > >> client machine. But the interpreter is now running on MY machine. Well > >> in a sandbox really. So how is that going to work? > > > Yeah, those are the paths on the machine where the binary was compiled > > (so, they are the standard paths on ubuntu). > > > Anyhow the filesystem can't (and shouldn't) be accessed from inside a > > browser page. > > Well, the local filesystem could be accessible with the user's > permission and this should be an option. > Hmm, I think this might be possible with the HTML5 File API. Would definitely be useful here. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 3, 12:13 pm, de...@web.de (Diez B. Roggisch) wrote: > A fun hack. Have you bothered to compare it to the PyPy javascript > backend - perfomance-wise, that is? > Gerry already gave a complete and accurate answer to the status of this project in comparison to PyPy and pyjamas. Regarding performance, this hack is not currently fast, primarily because the code is not optimized yet. But through a combination of optimizations on the side of Emscripten (getting all LLVM optimizations to work when compiling to JS) and on the side of the browsers (optimizing accesses on typed arrays in JS, etc.), then I hope the code will eventually run quite fast, even comparably to C. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 2, 5:55 pm, Gerry Reno wrote: > I tried printing sys.path and here is the output: > > ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/', > '/usr/local/lib/python2.7/plat-linux2', > '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', > '/usr/local/lib/lib-dynload'] > > Now, those paths must be on your machine because they are not on my > client machine. But the interpreter is now running on MY machine. Well > in a sandbox really. So how is that going to work? > Yeah, those are the paths on the machine where the binary was compiled (so, they are the standard paths on ubuntu). Anyhow the filesystem can't (and shouldn't) be accessed from inside a browser page. I think we will implement a minimal virtual filesystem here, just enough for stuff to work. The actual implementation would use HTML5 features like local storage etc. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 2, 4:58 pm, pyt...@bdurham.com wrote: > Azakai/Gerry, > > > Errors when using Firefox 3.6.3: > > I'm running Firefox 3.6.1.3 and the interpreter is running fine. > > I'm on Windows 7 Pro 64-bit. > > Malcolm Thanks for the info. To be honest I'm surprised it works there. I guess the error Gerry ran into depends on additional factors. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 2, 3:14 pm, Gerry Reno wrote: > On 01/02/2011 05:53 PM, azakai wrote: > > > On Jan 2, 1:01 pm, Gerry Reno wrote: > > >> 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. > > > I've only tested with Firefox 4. I'm surprised though that it wouldn't > > work on 3.6.3. Can you see what errors appear in the error console > > (control-shift-J)? > > Errors when using Firefox 3.6.3: > > script stack space quota is exhausted Ah, then yeah, it's the script stack issue I was afraid of. Then there's not really a way to run the demo on Firefox 3.6.x. It will work on Firefox 4 though, or other recent browsers. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 2, 1:01 pm, Gerry Reno wrote: > > 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. > I've only tested with Firefox 4. I'm surprised though that it wouldn't work on 3.6.3. Can you see what errors appear in the error console (control-shift-J)? If no errors appear, it might be a failure due to limited script stack space (which is fixed in FF4, and I guess is a problem in earlier versions). > > So what is happening is that the whole Python interpreter has been > converted to Javascript and is running the browser, is that correct? Yes. > > Ok, but the usual browser 'sandbox' constraints would still apply would > they not? Yes, the JavaScript is limited in the usual ways. So Python is running in a sandboxed manner. > > 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"? > Note that loading modules isn't implemented yet, but I'll work on it soon. The toolchain will be to use your normal makefiles and such, but replacing gcc with llvm-gcc or clang, so it generates LLVM bytecode instead of a normal binary. Then one would run the generated LLVM bytecode through Emscripten, which compiles it to JavaScript. So, the process should be fairly simple. - azakai -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 2, 5:52 am, "Octavian Rasnita" 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: CPython on the Web
On Jan 2, 5:42 am, pyt...@bdurham.com wrote: > > 1. Are there plans to support IE 7 or 8? I think it might run slowly there, but otherwise sure, it should run - the code is intended to be valid JavaScript (if it isn't, that's a bug). Currently though a minor issue prevents it from running on IE, I have been told (I don't have a Windows machine to test on myself), http://code.google.com/p/emscripten/issues/detail?id=22 > > 2. I'm not sure what you mean by non-static modules? Can we use modules > such as json, pickle/cPickle, StringIO/cStringIO? > Sorry, I should have been more clear. There isn't support for dlopen(), which opens dynamically linked libraries. That means that you can import libraries like sys, which are already linked into python. But loading a module that exists as a separate file won't work yet (but hopefully soon). > 3. Is there a virtual file system we can take advantage of so calls to > open() would work? > No, not yet, the libc implementation used just has stubs for input/ output stuff so far. Work in progress ;) - azakai -- http://mail.python.org/mailman/listinfo/python-list
CPython on the Web
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 -- http://mail.python.org/mailman/listinfo/python-list