Skip to content

Python implementation of traceback limit does not default to 1000 as documented in 3.13 #123596

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

Open
blhsing opened this issue Sep 2, 2024 · 6 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@blhsing
Copy link
Contributor

blhsing commented Sep 2, 2024

Bug report

Bug description:

According to the documentation of sys.tracebacklimit, it should default to 1000 if not set, so the following snippet:

import sys

def f():
    f()

sys.setrecursionlimit(2000)
f()

produces a traceback of 1000 frames as expected in 3.12:

Traceback (most recent call last):
  File "t.py", line 4, in f
    f()
    ~^^
  File "t.py", line 4, in f
    f()
    ~^^
  File "t.py", line 4, in f
    f()
    ~^^
  [Previous line repeated 997 more times]
RecursionError: maximum recursion depth exceeded

But in 3.13 and the current master, it produces a traceback of all 2000 frames:

Traceback (most recent call last):
  File "t.py", line 4, in f
    f()
    ~^^
  File "t.py", line 4, in f
    f()
    ~^^
  File "t.py", line 4, in f
    f()
    ~^^
  File "t.py", line 4, in f
    f()
    ~^^
  [Previous line repeated 1996 more times]
RecursionError: maximum recursion depth exceeded

This is because with issue #110721, traceback is now printed with the traceback module by default, and the traceback module defaults sys.tracebacklimit to None when not set:

limit = getattr(sys, 'tracebacklimit', None)

whereas the C implementation of the traceback printer has a proper default of 1000 for sys.tracebacklimit as documented:

#define PyTraceBack_LIMIT 1000

I will submit a PR to make 1000 the default value for sys.tracebacklimit in the Python implementation of the traceback module.

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

Linux, Windows

Linked PRs

@blhsing blhsing added the type-bug An unexpected behavior, bug, or error label Sep 2, 2024
@picnixz picnixz added the stdlib Python modules in the Lib dir label Sep 2, 2024
@cfbolz
Copy link
Contributor

cfbolz commented Sep 2, 2024

Nice find! When fixing you need to be careful not to change the behavior for existing explicit users of the traceback module. The traceback module has a special sentinel that is passed for 'builtin' traceback formatting, look for builtin_limit.

@rruuaanng
Copy link
Contributor

Are you still studying the problem? If you are ready to submit, maybe I will close my submission. Be sorry.:)

@blhsing
Copy link
Contributor Author

blhsing commented Oct 22, 2024

Are you still studying the problem? If you are ready to submit, maybe I will close my submission. Be sorry.:)

I went with the limit = getattr(sys, 'tracebacklimit', 1000) route in my attempt to fix the bug but had been dealing with a failed existing test. I think your approach of simply setting sys.tracebacklimit to 1000 is both easier and cleaner. 👍

@rruuaanng
Copy link
Contributor

I have fixed the C code regarding the sys.tracebacklimit attribute. I can close that commit in python so that your changes to traceback.py can be initiated. What do you think?

@rruuaanng
Copy link
Contributor

I have closed the PR for traceback.py. I'm sorry, but this is not a simple traceback.py problem. There is no sys.tracebacklimit attribute in sys. I have submitted the PR. You can continue to fix traceback.py.

@rruuaanng
Copy link
Contributor

@blhsing Are you still working on it? If you are done, you can submit a PR. My PR is waiting for your submission before it can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants