I have a script I wrote in python and it works fine but I was curious to see if I could speed it up. It basically is recursive script.
If I run it within normal python 2.7, it takes about 30 seconds. When I run the same thing using pypy than I get the following error:
RuntimeError: maximum recursion depth exceeded
I'm not sure what pypy is doing differently because I'm not modifying the script.
Can anyone help me understand what is going on?
Update: ok I figured it out. Increasing the limit helped but I think I was running the wrong file. I found a file under the bin directory called py.py and was using that. I'm not sure what the file does but its slower than normal python. I had to search and find 'pypy-c' seems to work now.
As you suggest in your update your problem was that you were using py.py (which is for running PyPy's interpreter on top of CPython). PyPy has a higher recursion limit than CPython normally. You can use sys.setrecursionlimit()
to increase the recursion limit, sys.getrecursionlimit()
does not provide the actual recursion limit.
PyPy 1.6.0:
>>>> sys.getrecursionlimit()
100
>>>> def infinite(level=0):
.... print level
.... return infinite(level+1)
....
>>> infinite()
<snip>
1010
Traceback (most recent call last):
File "<console>", line 2, in infinite
RuntimeError: maximum recursion depth exceeded
>>> sys.setrecursionlimit(sys.maxint)
>>> infinite()
<snip>
9769
zsh: segmentation fault pypy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With