New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'utils.in_a_shell()' : stack overflow. #119

Closed
gasparka opened this Issue Sep 1, 2016 · 7 comments

Comments

Projects
None yet
3 participants
@gasparka

gasparka commented Sep 1, 2016

Happens on Pycharm 2016.2.2, works fine on console.
Version: 0.6.1 (latest from pip)
Example:

from redbaron import RedBaron
import textwrap
code = textwrap.dedent("""\
    def a():
        pass""")
red = RedBaron(code)[0]
red.value.insert(0, 'a') # <- problem here

Result:

Fatal Python error: Cannot recover from stack overflow.

Current thread 0x00007fcd31630700 (most recent call first):
  File "python3.5/site-packages/redbaron/utils.py", line 38 in in_a_shell
  File "python3.5/site-packages/redbaron/base_nodes.py", line 946 in __repr__
  File "python3.5/collections/__init__.py", line 1081 in index
  File "python3.5/site-packages/redbaron/base_nodes.py", line 119 in get_holder_on_attribute
  File "python3.5/site-packages/redbaron/base_nodes.py", line 50 in __init__
  File "python3.5/site-packages/redbaron/base_nodes.py", line 840 in path
  File "python3.5/site-packages/redbaron/base_nodes.py", line 951 in __repr__
  File "python3.5/collections/__init__.py", line 1081 in index
  File "python3.5/site-packages/redbaron/base_nodes.py", line 119 in get_holder_on_attribute
  File "python3.5/site-packages/redbaron/base_nodes.py", line 50 in __init__
  File "python3.5/site-packages/redbaron/base_nodes.py", line 840 in path
  File "python3.5/site-packages/redbaron/base_nodes.py", line 951 in __repr__

I have currently set 'utils.in_a_shell()' default return to True instead of False. This fixes the problem but i am not sure if this is a correct way to do it.

Thanks for the good work :)

@b5y

This comment has been minimized.

Show comment
Hide comment
@b5y

b5y Sep 2, 2016

Contributor

You should avoid running large programs in PyCharm using RedBaron. I have had this error and solved it running program via terminal (without import sys). PyCharm has some memory usage restrictions and hence some problems. There is "binding" to terminal on the bottom of PyCharm window. Just use it. :)

Contributor

b5y commented Sep 2, 2016

You should avoid running large programs in PyCharm using RedBaron. I have had this error and solved it running program via terminal (without import sys). PyCharm has some memory usage restrictions and hence some problems. There is "binding" to terminal on the bottom of PyCharm window. Just use it. :)

@gasparka

This comment has been minimized.

Show comment
Hide comment
@gasparka

gasparka Sep 2, 2016

The snippet i posted is just minimal test to produce this error, i am not using PyCharm as a terminal replacement.
Problem is related to infinite recursion, which i would classify as a bug.

gasparka commented Sep 2, 2016

The snippet i posted is just minimal test to produce this error, i am not using PyCharm as a terminal replacement.
Problem is related to infinite recursion, which i would classify as a bug.

@b5y

This comment has been minimized.

Show comment
Hide comment
@b5y

b5y Sep 2, 2016

Contributor

I did not suggest you to use terminal instead of PyCharm. The advice was in running program, not in implementing.

I have tried with Python 2.7.12 and what I got if I run in PyCharm (last two lines):

return Path(self)
RuntimeError: maximum recursion depth exceeded while calling a Python object

Is is exactly what I mentioned on my previous comment.

And what I get if I run via terminal:

def a():
    a
    pass

So, it is the same thing as with Python 3.5 except error output.
The initial purpose of RedBaron was using it in terminal (IPython).

Actually, it is not a bug. If you try to add this line on your code:

redbaron.DEBUG = True

Everything will work fine.

Contributor

b5y commented Sep 2, 2016

I did not suggest you to use terminal instead of PyCharm. The advice was in running program, not in implementing.

I have tried with Python 2.7.12 and what I got if I run in PyCharm (last two lines):

return Path(self)
RuntimeError: maximum recursion depth exceeded while calling a Python object

Is is exactly what I mentioned on my previous comment.

And what I get if I run via terminal:

def a():
    a
    pass

So, it is the same thing as with Python 3.5 except error output.
The initial purpose of RedBaron was using it in terminal (IPython).

Actually, it is not a bug. If you try to add this line on your code:

redbaron.DEBUG = True

Everything will work fine.

@gasparka

This comment has been minimized.

Show comment
Hide comment
@gasparka

gasparka Sep 2, 2016

Clearly if i am using some development environment i want to also run code in that environment, think about debugging for example. Furthermore i have all my unit-tests failing because i am using pycharm's test integration.

Setting the DEBUG flag fixes the problem, but i believe some permanent fix is required as this issue will very likely rise for other people as well.

gasparka commented Sep 2, 2016

Clearly if i am using some development environment i want to also run code in that environment, think about debugging for example. Furthermore i have all my unit-tests failing because i am using pycharm's test integration.

Setting the DEBUG flag fixes the problem, but i believe some permanent fix is required as this issue will very likely rise for other people as well.

@b5y

This comment has been minimized.

Show comment
Hide comment
@b5y

b5y Sep 2, 2016

Contributor

There are another solutions:

  1. Changing IDE
  2. Debuging with pdb (using terminal)
  3. Splitting project to multiple pieces of code during testing/debugging (using PyCharm)

RedBaron project exists since early 2014. I don't think that we are only two persons who had this problem before. For instance, this large project uses RedBaron.

Contributor

b5y commented Sep 2, 2016

There are another solutions:

  1. Changing IDE
  2. Debuging with pdb (using terminal)
  3. Splitting project to multiple pieces of code during testing/debugging (using PyCharm)

RedBaron project exists since early 2014. I don't think that we are only two persons who had this problem before. For instance, this large project uses RedBaron.

@ibizaman

This comment has been minimized.

Show comment
Hide comment
@ibizaman

ibizaman Dec 20, 2016

Collaborator

@petspats so just running the program you showed produces that much recursion? I didn't check the code for this issues but that seems indeed like way too much recursion for such a "simple" parsing.
And although @b5y is right in that you could use something else to run the baron code, I totally understand you don't want that as I wouldn't want that either.

Collaborator

ibizaman commented Dec 20, 2016

@petspats so just running the program you showed produces that much recursion? I didn't check the code for this issues but that seems indeed like way too much recursion for such a "simple" parsing.
And although @b5y is right in that you could use something else to run the baron code, I totally understand you don't want that as I wouldn't want that either.

@ibizaman ibizaman closed this in #122 Dec 21, 2016

ibizaman added a commit that referenced this issue Dec 21, 2016

Merge pull request #122 from rojaster/repr_recursion_fix
Unsynchronized tree: __repr__ recursion fix for #119, #121
@gasparka

This comment has been minimized.

Show comment
Hide comment
@gasparka

gasparka Dec 21, 2016

@ibizaman
Tested on my system and issue is fixed as expected. Thanks for the good work guys 👍

gasparka commented Dec 21, 2016

@ibizaman
Tested on my system and issue is fixed as expected. Thanks for the good work guys 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment