-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Changes from 1 commit
3a12505
e0805c4
dfc6777
1525389
e660f07
5bc36e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -771,6 +771,28 @@ sys_excepthook_impl(PyObject *module, PyObject *exctype, PyObject *value, | |
| } | ||
|
|
||
|
|
||
| /*[clinic input] | ||
| sys.exception | ||
|
|
||
| Return the current exception. | ||
|
|
||
| Return the most recent exception caught by an except clause | ||
| in the current stack frame or in an older stack frame, or None | ||
| if no such exception exists. | ||
| [clinic start generated code]*/ | ||
|
|
||
| static PyObject * | ||
| sys_exception_impl(PyObject *module) | ||
| /*[clinic end generated code: output=2381ee2f25953e40 input=c88fbb94b6287431]*/ | ||
| { | ||
| _PyErr_StackItem *err_info = _PyErr_GetTopmostException(_PyThreadState_GET()); | ||
| if (err_info->exc_value != NULL) { | ||
| return Py_NewRef(err_info->exc_value); | ||
| } | ||
| Py_RETURN_NONE; | ||
| } | ||
|
|
||
|
|
||
| /*[clinic input] | ||
| sys.exc_info | ||
|
|
||
|
|
@@ -1963,6 +1985,7 @@ static PyMethodDef sys_methods[] = { | |
| SYS__CURRENT_FRAMES_METHODDEF | ||
| SYS__CURRENT_EXCEPTIONS_METHODDEF | ||
| SYS_DISPLAYHOOK_METHODDEF | ||
| SYS_EXCEPTION_METHODDEF | ||
| SYS_EXC_INFO_METHODDEF | ||
| SYS_EXCEPTHOOK_METHODDEF | ||
| SYS_EXIT_METHODDEF | ||
|
|
@@ -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\ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this "(thread safe)" note? It's not mentioned anywhere else.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the other functions in sys, like getrefcount, not thread safe?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| exc_info() -- return thread-safe information about the current exception\n\ | ||
| exit() -- exit the interpreter by raising SystemExit\n\ | ||
| getdlopenflags() -- returns flags to be used for dlopen() calls\n\ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.