Hi,
@alexmalyshev proposes adding PyUnstable_DumpTraceback() and PyUnstable_DumpTracebackThreads() functions to dump the Python traceback to a file descriptor:
const char* PyUnstable_DumpTraceback(int fd, PyThreadState *tstate);
const char* PyUnstable_DumpTracebackThreads(int fd, PyInterpreterState *interp, PyThreadState *current_tstate);
These functions are safe to use from signal handlers. The caller does not need to hold an attached thread state.
If PyUnstable_DumpTraceback() or PyUnstable_DumpTracebackThreads() cannot dump the traceback, it returns an error message. The caller is free to ignore it, or to report it someho to the user. It cannot raise an exception since it can be called without an attached thread state.
See the issue and the pull request. See the pull request for the whole API.
UPDATE: Change PyUnstable_DumpTraceback() return type from void to const char*.
Vote to add these 2 functions:
Hi,
@alexmalyshev proposes adding
PyUnstable_DumpTraceback()andPyUnstable_DumpTracebackThreads()functions to dump the Python traceback to a file descriptor:These functions are safe to use from signal handlers. The caller does not need to hold an attached thread state.
If
PyUnstable_DumpTraceback()orPyUnstable_DumpTracebackThreads()cannot dump the traceback, it returns an error message. The caller is free to ignore it, or to report it someho to the user. It cannot raise an exception since it can be called without an attached thread state.See the issue and the pull request. See the pull request for the whole API.
UPDATE: Change
PyUnstable_DumpTraceback()return type fromvoidtoconst char*.Vote to add these 2 functions: