Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-46328: added sys.exception() #30514

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

Merged
merged 6 commits into from
Jan 13, 2022

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Jan 10, 2022

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.

Please document the new function in Doc/whatsnew/3.11.rst.

@@ -2457,6 +2480,7 @@ Functions:\n\
\n\
displayhook() -- print an object to the screen, and save it in builtins._\n\
excepthook() -- print an exception and its traceback to sys.stderr\n\
exception() -- return the current exception (thread safe)\n\
Copy link
Member

Choose a reason for hiding this comment

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

What is this "(thread safe)" note? It's not mentioned anywhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

The next line for exc_info mentions it's thread-safe, so I didn't want it to look like this isn't. But maybe I should remove it from both lines?

Copy link
Member

Choose a reason for hiding this comment

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

My concern is more that it's only in help(sys), but nowhere else. If it's thread safe and this information matters, it should be in the documentation as well. Maybe also in the function docstring.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don’t know if it matters. This info is thread specific anyway, so you would assume this is thread safe (this is mentioned in the doc).

Copy link
Member Author

Choose a reason for hiding this comment

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

Are the other functions in sys, like getrefcount, not thread safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it could be that the intention in the help line for exc_info was to say that it’s a thread-specific value, but it was worded incorrectly. I’d change both to say this instead of thread-safe.

Copy link
Member

Choose a reason for hiding this comment

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

Most functions implemented in C are thread-safe. I agree, remove the mention from both functions.

The exact behavior can be elaborated in the documentation, if needed.

Yeah, the current exception is per-thread.

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.

LGTM. But I suggest to remove "(thread safe)" from sys docstring.

@iritkatriel iritkatriel merged commit c590b58 into python:main Jan 13, 2022
@vstinner
Copy link
Member

Nice @iritkatriel! That looks like an useful feature ;-) I dislike sys.exc_info() which smells like a legacy of Python 2 exceptions.

@iritkatriel iritkatriel deleted the bpo-46328-sys-exception branch January 13, 2022 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants