Live data from Hacker News

PyPy.js: A fast, compliant Python implementation for the web

pypyjs.org

111–120 of 144 posts

Re: PyPy.js: A fast, compliant Python implementation for the web

#111
post #17

Earlier quoted context omitted.

Glorious indeed. At least three levels of abstraction, two JITs, and a host of supporting code. Can we add some more layers like an emulator or get recursive by getting something like Pyasm running inside it?

I work on a machine that has two hypervisors, one third in plan, and more abstraction layers than a lasagna software. It is still very very efficient.

Fast(ish) != efficient. Your setup is categorically inefficient. That may be fine for your use case, but let's not lie to ourselves.

Re: PyPy.js: A fast, compliant Python implementation for the web

#112
post #46

Earlier quoted context omitted.

I'm loving this, my head is reeling with the glint of possibilities import js js.globals.console.log('hi!'*5)

Seems to be some issues with the interop still, eg: import js >>> "globals" in dir(js) True >>> "console" in dir(js.globals) False >>> js >>> js.globals.console So apparently introspection doesn't quite work with the wrapped js. Also, if you try: "[ i for i in js.globals]" (or equivalently iterate/loop over the globals-object) - the whole repl/tab hangs. Not really an issue for running business logic in the browser,…

The introspection bit is because js.globals is implemented with a fancy __getattr__ but doesn't have a __dir__. In general, dir() is not reliable in the face of custom __getattr__ implementations unless the implementor goes out of the way to make it work.

Re: PyPy.js: A fast, compliant Python implementation for the web

#113
post #9

I watched the presentation in Pycon 2015[1], and I really liked how honest/aware they are about the challenges and tradeoffs (so far, the performance it's pretty bad compared to javascript, and the download size is still an issue). At the end is answered why python can't be directly included in Firefox or other browsers(the presenter/main developer works for Mozilla) [1] https://www.youtube.com/watch?v=PiBfOFqDIAI

For historical context, early IE browsers weren't hardcoded to use JavaScript. We know about VBScript, but really there was a generic framework called Active Scripting that would allow any other language to be plugged in.

Python was one of those languages. You could download an ActivePython distribution and start being able to run python in your web page with a tag.

I'm not sure if this still works in current IE versions. It might.

Re: PyPy.js: A fast, compliant Python implementation for the web

#114

Earlier quoted context omitted.

I wonder if Python could be embedded as an addon.

Of course it could. But that would defeat the point, because support wouldn't be widespread enough for any real use (unless you're just using it for an intranet site or something).

As usual, everyone devalues the benefits of progressive enhancement. Add-on would be a great way to get the ball rolling, as long as your website works without it too.

Re: PyPy.js: A fast, compliant Python implementation for the web

#115
Looks like there are some issues to iron out...

  >>> from datetime import datetime
  >>> datetime.now()
  Traceback (most recent call last):
    File "", line 1, in 
    File "/lib/pypyjs/lib_pypy/datetime.py", line 1548, in now
      return cls.fromtimestamp(t, tz)
    File "/lib/pypyjs/lib_pypy/datetime.py", line 1522, in fromtimestamp
      result = cls(y, m, d, hh, mm, ss, us, tz)
    File "/lib/pypyjs/lib_pypy/datetime.py", line 1459, in __new__
      hour, minute, second, microsecond)
    File "/lib/pypyjs/lib_pypy/datetime.py", line 312, in _check_time_fields
      raise ValueError('microsecond must be in 0..999999', microsecond)
  ValueError: ('microsecond must be in 0..999999', 1716000)

Re: PyPy.js: A fast, compliant Python implementation for the web

#116

Looks like there are some issues to iron out... >>> from datetime import datetime >>> datetime.now() Traceback (most recent call last): File " ", line 1, in File "/lib/pypyjs/lib_pypy/datetime.py", line 1548, in now return cls.fromtimestamp(t, tz) File "/lib/pypyjs/lib_pypy/datetime.py", line 1522, in fromtimestamp result = cls(y, m, d, hh, mm, ss, us, tz) File "/lib/pypyjs/lib_pypy/datetime.py", line 1459, in __new_…

[deleted]

Re: PyPy.js: A fast, compliant Python implementation for the web

#118
post #84

Earlier quoted context omitted.

Potentially just one JIT, right? asm.js is AOT compiled on Firefox.

No, because it's "AOT" compiled when it's downloaded or executed (since you have one JIT, you can't AOT compile what it produces). So you can think about it as "just" one JIT, but a very inefficient one

> since you have one JIT, you can't AOT compile what it produces

I'm not sure what this means, but if you mean that Firefox doesn't cache compiled asm.js code, that's not true. It does [1].

[1]: https://blog.mozilla.org/luke/2014/01/14/asm-js-aot-compilat...

Re: PyPy.js: A fast, compliant Python implementation for the web

#119
post #18

Sample code to execute some Javascript code inside PyPy.js. I couldn't find any examples. import js js.eval("console.log(\"hi!\")")

It's a bit messy, but: js.eval('var div = document.createElement("div"); div.style.width = "100px"; div.style.height = "100px"; div.style.background = "red"; div.style.color = "white"; div.innerHTML = "Hello"; document.body.appendChild(div);'); manages to append a div. -- Directly modifying document.body.innerHTML in any way seems to hang it. Both: js.eval('document.body.innerHTML += " ";'); js.globals.document.body.…

It's more fun doing this, since jQuery is already on the page:

    import js
    jq = js.eval("$")
    first_line = jq(jq(".container p")[0])
    first_line.text("jQuery was here")

Re: PyPy.js: A fast, compliant Python implementation for the web

#120

Looks like there are some issues to iron out... >>> from datetime import datetime >>> datetime.now() Traceback (most recent call last): File " ", line 1, in File "/lib/pypyjs/lib_pypy/datetime.py", line 1548, in now return cls.fromtimestamp(t, tz) File "/lib/pypyjs/lib_pypy/datetime.py", line 1522, in fromtimestamp result = cls(y, m, d, hh, mm, ss, us, tz) File "/lib/pypyjs/lib_pypy/datetime.py", line 1459, in __new_…

That works now.
Post reply on HN