Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

Bug: a program does not terminate

Open nockty opened this issue 7 years ago • 2 comments

Summary: When I call semver with certain parameters, the program doesn't terminate.

Steps to reproduce: Install the semver NPM package (mine is version 5.5.1) and use it in Python (I have version 3.6.5).

import js2py
semver = js2py.require('semver')
semver.satisfies('1.2.3-beta.1', '^1.2.3-beta.1')

Expected result: It should return True. (That's what I get when I run it with Node.)

Actual result: It doesn't terminate. If it can help, this is what I got when I interrupted the program:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.6/site-packages/js2py/base.py", line 1121, in __call__
    return to_python(parent._obj.callprop(meth, *args))
  File "/lib/python3.6/site-packages/js2py/base.py", line 939, in callprop
    return cand.call(self, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 1022, in PyJsHoisted_satisfies_
  File "/lib/python3.6/site-packages/js2py/base.py", line 939, in callprop
    return cand.call(self, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 1728, in PyJs_anonymous_57_
  File "/lib/python3.6/site-packages/js2py/base.py", line 899, in __call__
    return self.call(self.GlobalObject, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 983, in PyJsHoisted_testSet_
  File "/lib/python3.6/site-packages/js2py/base.py", line 939, in callprop
    return cand.call(self, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 1579, in PyJs_anonymous_33_
  File "/lib/python3.6/site-packages/js2py/base.py", line 899, in __call__
    return self.call(self.GlobalObject, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 640, in PyJsHoisted_cmp_
  File "/lib/python3.6/site-packages/js2py/base.py", line 899, in __call__
    return self.call(self.GlobalObject, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 586, in PyJsHoisted_gte_
  File "/lib/python3.6/site-packages/js2py/base.py", line 899, in __call__
    return self.call(self.GlobalObject, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 511, in PyJsHoisted_compare_
  File "/lib/python3.6/site-packages/js2py/base.py", line 939, in callprop
    return cand.call(self, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 1369, in PyJs_anonymous_24_
  File "/lib/python3.6/site-packages/js2py/base.py", line 939, in callprop
    return cand.call(self, args)
  File "/lib/python3.6/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "<string>", line 1399, in PyJs_anonymous_26_
  File "/lib/python3.6/site-packages/js2py/base.py", line 897, in __call__
    if not self.is_callable():
KeyboardInterrupt

nockty avatar Sep 06 '18 22:09 nockty

Yeah, Js2Py has some bugs and in some cases large Js libraries use constructs that hit those edge cases. In this case it is very hard to debug the problem, maybe simply Js2Py is still executig the code? Remember that python is about 100 times slower than C and the translated code is say, 10 times slower than perfect manual translation to python, this means that Js2Py is about 1000 times slower than Node! So if the command takes 3 seconds when run from node it will take an hour when run fron js2py :)

PiotrDabkowski avatar Sep 07 '18 08:09 PiotrDabkowski

Yeah, you may be right. What confused me is that if I run, say, semver.satisfies('1.2.3', '^1.2.3') with js2py, then I immediately get the result (and it's the same for most of the parameters). Maybe there are some cases (for instance semver.satisfies('1.2.3-beta.1', '^1.2.3-beta.1')) where Node takes a lot more time to compute the result (but it's still very fast) and thus it takes a huge amount of time with js2py. Thanks for your answer!

nockty avatar Sep 07 '18 17:09 nockty