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
3.x ignores sys.tracebacklimit=0 #56485
Comments
Python 3.x doesn't honor sys.tracebacklimit=0 According to Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
p3> import sys
p3> sys.tracebacklimit = 0
p3>
p3> def f(x):
... return f(x-1) if x else 0/0
...
p3> f(5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
File "<stdin>", line 2, in f
File "<stdin>", line 2, in f
File "<stdin>", line 2, in f
File "<stdin>", line 2, in f
File "<stdin>", line 2, in f
ZeroDivisionError: division by zero
p3> |
Originally reported by Thorsten Kampe in comp.lang.python 2011-5-27 |
This was changed a long time ago with 565012d1123d |
Is this the intended behavior then? I don't get the rationale for that change. There is no way to completely supress traceback information now; for sys.tracebacklimit to be of any significance, it must be >= 1; 0 and negative values behave the same as it not being set (that is, a full traceback is printed). |
Either code or doc must change (with 'version changed' note). Doc: "The default is 1000. When set to 0 or less, all traceback information is suppressed and only the exception type and value are printed." Christian's patch: "values <= 0 are replaced with a default value to avoid infinite recursion and other issues." Default is 1000. I do not see the logic of changing 'nothing' to 'everything'. I am puzzled how printing nothing causes infinite recursion. |
This patch fixes the issue. I have also added 2 test cases to make sure it works. |
Update patch with better assertions |
Do you mind to create a pull request on GitHub Anand? bpo-31949 fixes this and several other bugs in PyTraceBack_Print(), but it may be worth to fix this bug first, especially if the patch contains tests. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: