Skip to content

gh-123596: Add missing tracebacklimit attribute to sys module #125719

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rruuaanng
Copy link
Contributor

@rruuaanng rruuaanng commented Oct 19, 2024

test code:

import sys

def f():
    f()

sys.setrecursionlimit(2000)
f()

In fact, in

_PySys_UpdateConfig(PyThreadState *tstate)

the sys.tracebacklimit attribute isn't set.
However, in
limitv = PySys_GetObject("tracebacklimit");

it tries to get the attribute and performs the same behavior in
limit = getattr(sys, 'tracebacklimit', None)

Therefore, the number of tracebacks is inaccurate.

@rruuaanng rruuaanng marked this pull request as ready for review October 19, 2024 03:22
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, submitting your own PR is uncourteous when someone said they would already. For future reference, you should have asked @blhsing whether he was still working on it.

A few other things here:

  • Needs a NEWS entry--this is a user-facing change.
  • Please add a test.

This is a recurring issue, so I really suggest you read the pull request section of the devguide.

Regarding the technical aspect of this PR, don't redefine PyTraceBack_LIMIT. I agree that it should be in a header file, but not pycore_call.h. The proper place to move it to is pycore_traceback.h, and then include that in sysmodule.c if it isn't already.

Thanks!

@rruuaanng
Copy link
Contributor Author

Oh, I'm sorry, it seems that it has been a long time since it initiated the submission. It seems that it doesn't have time because it is busy. So I think maybe I can help finish it.

@rruuaanng
Copy link
Contributor Author

rruuaanng commented Oct 20, 2024

Hi, submitting your own PR is uncourteous when someone said they would already. For future reference, you should have asked @blhsing whether he was still working on it.

A few other things here:

* Needs a NEWS entry--this is a user-facing change.

* Please add a test.

This is a recurring issue, so I really suggest you read the pull request section of the devguide.

Regarding the technical aspect of this PR, don't redefine PyTraceBack_LIMIT. I agree that it should be in a header file, but not pycore_call.h. The proper place to move it to is pycore_traceback.h, and then include that in sysmodule.c if it isn't already.

Thanks!

There are two reasons why I don't add NEWS:

  1. It's already in the documentation. It's just not implemented in C.
  2. Because it already exists in the document, the user knows about it. So I don't think it needs to be reiterated.

exist test:

def test_sys_tracebacklimit(self):

exist docs:

cpython/Doc/library/sys.rst

Lines 1917 to 1922 in e924bb6

.. data:: tracebacklimit
When this variable is set to an integer value, it determines the maximum number
of levels of traceback information printed when an unhandled exception occurs.
The default is ``1000``. When set to ``0`` or less, all traceback information
is suppressed and only the exception type and value are printed.

@ZeroIntensity
Copy link
Member

No, it's a bug that it differs from the docs, so we need to document that we fixed it with a NEWS entry.

That's the right place to put the test, but you need to add something to make sure that this issue was fixed.

@rruuaanng
Copy link
Contributor Author

I think I'm making a change. Thank for your reply.

@rruuaanng
Copy link
Contributor Author

It seems that there is a problem with the CI service's documentation build that does not seem to be caused by my commits. Maybe I should open an issue.

0s
Run xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest
make: Entering directory '/home/runner/work/cpython/cpython/Doc'
make[1]: Entering directory '/home/runner/work/cpython/cpython/Doc'
mkdir -p build

Missing the required blurb or sphinx-build tools.
Please run 'make venv' to install local copies.

make[1]: *** [Makefile:55: build] Error 1
make[1]: Leaving directory '/home/runner/work/cpython/cpython/Doc'
Testing of doctests in the sources finished, look at the results in build/doctest/output.txt
make: *** [Makefile:134: doctest] Error 1
make: Leaving directory '/home/runner/work/cpython/cpython/Doc'

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before adding sys.tracebacklimit, I would prefer to fix #123596 : fix traceback.py limit when sys.tracebacklimit is not defined.

I understand that the fix is just about replacing getattr(sys, 'tracebacklimit', None) with getattr(sys, 'tracebacklimit', 1_000), but tests should be written for that.

@bedevere-app
Copy link

bedevere-app bot commented Oct 20, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@rruuaanng
Copy link
Contributor Author

I personally think that if we only replace getattr(sys, 'tracebacklimit', None) with getattr(sys, 'tracebacklimit', 1_000), there is actually a problem that has not been fundamentally solved, that is, limitv = PySys_GetObject("tracebacklimit"); cannot obtain the corresponding attributes.
I think.

@vstinner
Copy link
Member

I'm not against adding sys.tracebacklimit. But I would prefer to fix the bug when the attribute doesn't exist.

@rruuaanng
Copy link
Contributor Author

Maybe I should also make changes for python so that when the tracebacklimit is really not reached, it can be set to 1000.

@vstinner
Copy link
Member

@rruuaanng: Apparently, you don't listen to my advices, so I will stop reviewing your PR. I asked you to create a new PR to fix traceback.py and add new tests only for this change, but you ignore your request.

@rruuaanng
Copy link
Contributor Author

rruuaanng commented Oct 21, 2024

Oh, I'm sorry victor. I think I misunderstood you. I'll make the change now.
Edit:
I thought you wanted me to make changes based on this PR. So I'm sorry.

@rruuaanng rruuaanng changed the title gh-123596: Fix incorrect number of stack tracebacks gh-123596: Add missing tracebacklimit attribute to sys module Oct 21, 2024
@rruuaanng
Copy link
Contributor Author

I'll rollback this PR so that it only adds the sys.tracebacklimit attribute.

@rruuaanng
Copy link
Contributor Author

#125777

@rruuaanng
Copy link
Contributor Author

Maybe remove the DO-NOT-MERGE if you can :)

@ZeroIntensity
Copy link
Member

This doesn't have the DO-NOT-MERGE label. You need to trigger the bot to move it to the next stage.

@rruuaanng
Copy link
Contributor Author

I didn't expect the Spanish Inquisition

@bedevere-app
Copy link

bedevere-app bot commented Oct 22, 2024

Nobody expects the Spanish Inquisition!

@vstinner: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from vstinner October 22, 2024 01:42
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks ok. Take my review as provisional, though--Victor certainly knows more about the underlying issue than I do.

@rruuaanng
Copy link
Contributor Author

Thank for your reviewer Peter!

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow Victors remark:

Before adding sys.tracebacklimit, I would prefer to fix #123596 : fix traceback.py limit when sys.tracebacklimit is not defined.

I understand that the fix is just about replacing getattr(sys, 'tracebacklimit', None) with getattr(sys, 'tracebacklimit', 1_000), but tests should be written for that.

@bedevere-app
Copy link

bedevere-app bot commented Nov 5, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@erlend-aasland erlend-aasland marked this pull request as draft November 5, 2024 11:05
@rruuaanng

This comment was marked as off-topic.

@rruuaanng rruuaanng marked this pull request as ready for review November 8, 2024 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants