Skip to content
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

Loguru infinite recursion traceback loop #1044

Open
mpenning opened this issue Dec 6, 2023 · 1 comment
Open

Loguru infinite recursion traceback loop #1044

mpenning opened this issue Dec 6, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@mpenning
Copy link

mpenning commented Dec 6, 2023

My problem is if I hit a bug in certain methods, I get an infinite traceback from loguru. I love loguru when it works, but digging into the infinite recursion is a serious drag on my development because even with a multi-thousand-line scrollback buffer, I still can't hit control-c fast enough to interrupt the infinite loop of loguru messages and find the real cause of the problem (i.e. I have two problems, loguru inifinte recursion and the ciscoconfparse2 bug that caused it).

Is there a way to get loguru to stop printing tracebacks in an infinite loop?

You can reproduce the infinite recursion loop as follows:

  • Install loguru==0.7.2
  • git clone ciscoconfparse2 to my local system
  • cd ciscoconfparse2
  • checkout hash 1a7b88d72c5a86a673ba8d4ed18316036c65fded
  • run this script (python versions don't seem to matter... I have seen this problem over and over for months with a variety of python versions):
from loguru import logger

from ciscoconfparse2 import CiscoConParse

parse = CiscoConfParse("tests/fixtures/configs/sample_01.junos", syntax="junos", factory=False)
print(parse)
for obj in parse.objs:
    print(obj)
@mpenning mpenning changed the title Loguru maximum recursion infinite loop Loguru infinite recursion traceback loop Dec 6, 2023
@Delgan
Copy link
Owner

Delgan commented Dec 22, 2023

Hi @mpenning.

Sorry you're experiencing difficulties with Loguru, and thanks for the reproducible example. It boils down to the following:

from loguru import logger


class Foo:
    @logger.catch(reraise=True)
    def __repr__(self):
        raise ValueError("Something went wrong")


if __name__ == "__main__":
    foo = Foo()
    print(foo)

It's definitely a problem with diagnose=True which causes infinite recursion if the exception is raised in __repr__, since v can't be printed:

def _format_value(self, v):
try:
v = repr(v)
except Exception:
v = "<unprintable %s object>" % type(v).__name__

I'll try to implement a fix. In the meantime, I advise to use diagnose=False or remove @logger.catch() decorator from __repr__() methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants