This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 3.x ignores sys.tracebacklimit=0
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Bugs in PyTraceBack_Print()
View: 31949
Assigned To: serhiy.storchaka Nosy List: amaury.forgeotdarc, chillaranand, christian.heimes, ggenellina, matrixise, serhiy.storchaka, terry.reedy, vstinner
Priority: normal Keywords: easy, patch

Created on 2011-06-07 08:48 by ggenellina, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tracebacklimitbug.py ggenellina, 2011-06-07 08:48
Limit-traceback-if-sys.tracebacklimit-is-set.patch chillaranand, 2016-12-27 11:18 review
Limit-traceback-if-sys.tracebacklimit-is-set.patch chillaranand, 2017-01-02 04:58 review
Messages (8)
msg137792 - (view) Author: Gabriel Genellina (ggenellina) Date: 2011-06-07 08:48
Python 3.x doesn't honor sys.tracebacklimit=0

According to 
http://docs.python.org/py3k/library/sys.html#sys.tracebacklimit
when set to 0, it should not print any stack trace, but it does.

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>
msg137793 - (view) Author: Gabriel Genellina (ggenellina) Date: 2011-06-07 08:50
Originally reported by Thorsten Kampe in comp.lang.python 2011-5-27
<http://permalink.gmane.org/gmane.comp.python.general/691496>
msg137794 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-06-07 09:10
This was changed a long time ago with 565012d1123d
msg137893 - (view) Author: Gabriel Genellina (ggenellina) Date: 2011-06-08 02:09
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).
msg138147 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-06-11 02:17
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.
msg284084 - (view) Author: Anand Reddy Pandikunta (chillaranand) * Date: 2016-12-27 11:18
This patch fixes the issue. I have also added 2 test cases to make sure it works.
msg284463 - (view) Author: Anand Reddy Pandikunta (chillaranand) * Date: 2017-01-02 04:58
Update patch with better assertions
msg305597 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-05 14:55
Do you mind to create a pull request on GitHub Anand?

Issue31949 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.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56485
2017-11-20 18:05:52serhiy.storchakasetstatus: open -> closed
superseder: Bugs in PyTraceBack_Print()
resolution: duplicate
stage: needs patch -> resolved
2017-11-05 14:55:19serhiy.storchakasetversions: + Python 3.7, - Python 3.5
nosy: + serhiy.storchaka

messages: + msg305597

assignee: docs@python -> serhiy.storchaka
components: - Documentation
2017-01-02 04:58:13chillaranandsetfiles: + Limit-traceback-if-sys.tracebacklimit-is-set.patch

messages: + msg284463
2016-12-27 11:19:00chillaranandsetfiles: + Limit-traceback-if-sys.tracebacklimit-is-set.patch

messages: + msg284084
keywords: + patch
nosy: + chillaranand, - docs@python
2016-08-08 06:01:57matrixisesetnosy: + matrixise
2016-08-05 22:34:26berker.peksagsetkeywords: + easy
stage: needs patch
type: behavior
versions: + Python 3.5, Python 3.6, - Python 3.1, Python 3.2
2014-08-08 03:28:13ned.deilylinkissue22169 superseder
2011-06-11 02:17:34terry.reedysetnosy: + christian.heimes, terry.reedy, docs@python
messages: + msg138147

assignee: docs@python
components: + Documentation
2011-06-08 02:09:11ggenellinasetmessages: + msg137893
2011-06-07 09:22:27vstinnersetnosy: + vstinner
2011-06-07 09:10:18amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg137794
2011-06-07 08:50:17ggenellinasetmessages: + msg137793
2011-06-07 08:48:21ggenellinacreate