gh-145559: Add PyUnstable_DumpTraceback() and PyUnstable_DumpTracebackThreads()#145560
gh-145559: Add PyUnstable_DumpTraceback() and PyUnstable_DumpTracebackThreads()#145560alexmalyshev wants to merge 12 commits intopython:mainfrom
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Rather than exporting internal C API functions, I would prefer to promote them as public or PyUnstable functions. |
cb5cf36 to
d7f6643
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Made them PyUnsafe_ functions. I believe that the mentions to them in the configure and emscripten files can just be deleted now that they'll be public. |
|
I believe they should have |
Ack I always make this mistake... |
d7f6643 to
28803eb
Compare
…functions These functions stopped being exported in python#107215. However, they are the only way to print a Python stacktrace safely from a signal handler, making them very useful for extensions. Re-export them as PyUnstable functions.
28803eb to
d0c95ed
Compare
|
Please, try to avoid force-push. |
|
!buildbot emscripten |
|
🤖 New build scheduled with the buildbot fleet by @freakboy3742 for commit 538a1cd 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F145560%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
ZeroIntensity
left a comment
There was a problem hiding this comment.
Note that PyUnstable_DumpTracebackThreads does not work well on the free-threaded build, because other threads may exit and delete their PyThreadState *. I think it's worth adding a warning for that. Here's an example:
.. warning::
On the :term:`free-threaded build`, this function is not thread-safe. If
another thread deletes its :term:`thread state` while this function is being
called, the process will likely crash.Comment says 100, but it appears to have been 500 since 2012, 54f939b.
ZeroIntensity
left a comment
There was a problem hiding this comment.
One little issue with the blurb entry, but otherwise this looks good.
Misc/NEWS.d/next/C_API/2026-03-06-21-50-48.gh-issue-145559.AiXgHq.rst
Outdated
Show resolved
Hide resolved
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
It's unusual that PyUnstable_DumpTracebackThreads() returns an error message on error rather than raising an exception, but it's explained by the fact that the function can be called without an attached thread thread.
|
I created capi-workgroup/decisions#101 to get the API reviewed by the C API Working Group. |
Doc/c-api/exceptions.rst
Outdated
| 100 frames; further frames are truncated with the line ``...``. | ||
|
|
||
| This function will return ``NULL`` on success, or an error message on error. | ||
| It will also write this error message to *fd*. |
There was a problem hiding this comment.
Hum, I suggest to remove "It will also write this error message to fd." sentence. I'm not sure that it is always a good idea to write the error message to fd.
There was a problem hiding this comment.
I thought that was what the C API discussion was about, writing the string result over to the file (when it's non-NULL). Did I misunderstand?
There was a problem hiding this comment.
The function is supposed to dump debug information to fd. It can safely dump this message there, to simplify debugging.
There was a problem hiding this comment.
PyUnstable_DumpTraceback() should either write the error message to fd and return NULL, or not write into fd and return an error message. Doing both sounds redundant to me.
Currently, _Py_DumpTracebackThreads() returns an error message when it knows that it will not be able to output anything useful since it lacks an important data to do its work. For example, it returns an error message if it fails to get the current thread state.
There was a problem hiding this comment.
or not write into fd and return an error message.
I think this is simpler, updated the doc for PyUnstable_DumpTraceback().
Do we still want to do the extra debug logging for PyUnstable_DumpTracebackThreads() then, or shall we update that to also only return the const char*?
These functions stopped being exported in #107215. However, they are the only way to print a Python stacktrace safely from a signal handler, making them very useful for extensions. Re-export them.