Live data from Hacker News

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

pypyjs.org

131–140 of 144 posts

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

#131
post #46

Earlier quoted context omitted.

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.

Oh, right. I didn't consider that:

  Welcome to PyPy.js!
  >>> import js
  >>> "console" in js.globals
  True
  >>> "console" in dir(js.globals)
  False

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

#132
post #96
post #49

Earlier quoted context omitted.

I was more disappointed (but not surprised!) that "import pip" didn't work. If it did (and it has big ramifications for how much of "python" (for some definition of "python" that includes most of the standard library) works. Eg sockets, interacting with some sort of "local" "file-system" etc) one could (this is handy if working on windows, and running python via cmd-r python.exe): import pip # pip.main expects a list…

That would be a total security nightmare and hopefully it's never going to happen. I'd be happy enough with serving .py files with the exact same restrictions and privileges that JS libraries have now.

How is that worse than javascript loading javascript via AJAX?

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

#133
post #84

Earlier quoted context omitted.

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...

So look. PyPy compiles bits and pieces of code generating assembler. This assembler then gets to be turned into Javascript (asm.js) which needs to be parsed and compiled. All of this happens at runtime and while you can technically call the second piece of it AOT, it's essentially a double JIT or at least you pay the cost of double jitting. The equivalent in C would be generating C at runtime and sending it through gcc/clang.

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

#134
post #85

Earlier quoted context omitted.

I believe this only addresses the download size and not the crazy warmup (you still reparse it etc.)

Not quite. At least Firefox caches compiled asm.js.

You can't cache JITted code (so JIT produced by pypy.js) because it'll be different each time.

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

#135
post #134

Earlier quoted context omitted.

Not quite. At least Firefox caches compiled asm.js.

You can't cache JITted code (so JIT produced by pypy.js) because it'll be different each time.

Ah, sure.

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

#136
post #68

Earlier quoted context omitted.

Only because the browser vendors are too scared (for whatever reason, legitimate or otherwise) to add extra languages to the mix, like python.

"vendors are too scared (for whatever reason, legitimate or otherwise) to add extra languages to the mix, like python." Tried python server-side, mod_python and got lots of issues with formatting. Not syntax or mixed tab/spaces but one-off spacing errors. I realised then, Python used this way has problems. Could be fixed though.

One-off spacing errors? That doesn't sound right at all... Do you have an example?

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

#137

I think there is no point in trying to emulate different language semantics on top of JavaScript. asm.js is a weird hack that lives in a totally different world than actual browser APIs (e.g. the DOM), and you have to emulate your entire runtime and environment to get anything useful, which means your binary is going to be huge (as in this example, but similar things apply). Emulating better semantics than JS based o…

> That'd be TypeScript. Or CoffeeScript. Or Dart. Or this. In fact, here's a whole big long list of other languages. Most of which don't use the asm.js "weird hack". https://github.com/jashkenas/coffeescript/wiki/List-of-langu...

one weird hack to run assembler-like code in the browser!

developers hate him!

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

#138
post #136

Earlier quoted context omitted.

"vendors are too scared (for whatever reason, legitimate or otherwise) to add extra languages to the mix, like python." Tried python server-side, mod_python and got lots of issues with formatting. Not syntax or mixed tab/spaces but one-off spacing errors. I realised then, Python used this way has problems. Could be fixed though.

One-off spacing errors? That doesn't sound right at all... Do you have an example?

ages ago @zo1, I do see similar problems now if I shift from *nux/vim toolchain to win/idle which by default uses 'Python standard: 4 spaces!' but still throws random format error parsing on default code edits.

I don't like the fact python code stops working randomly if I write it in one environment then touch (edit) in another. Never have this problem with C or JS.

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

#139

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.

Does it?

  >>> 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 1511, in fromtimestamp
      us = _round(frac * 1e6)
    File "/lib/pypyjs/lib_pypy/datetime.py", line 28, in _round
      return int(_math.floor(x + 0.5) if x >= 0.0 else _math.ceil(x - 0.5))
  ValueError: cannot convert float NaN to integer

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

#140
post #136

Earlier quoted context omitted.

One-off spacing errors? That doesn't sound right at all... Do you have an example?

ages ago @zo1, I do see similar problems now if I shift from *nux/vim toolchain to win/idle which by default uses 'Python standard: 4 spaces!' but still throws random format error parsing on default code edits. I don't like the fact python code stops working randomly if I write it in one environment then touch (edit) in another. Never have this problem with C or JS.

I have only ever had issues like that when I worked on an actual Python checker where I had to keep BAD code in my tests to ensure the checks worked.

I've never ( read 99.999% of the time I've performed the task ) had issues with Python formatting that weren't my own fault, everyone makes mistakes after all. I routinely edit the same Python files in Vim, Nano, Sublime Text, Atom, and PyCharm, and even jumping between all those editors, they have never "damaged" the formatting and created syntax errors in my code.

I can only surmise that some of the things you used or even just your vim config was setup poorly for Python work.

Post reply on HN