Skip to content

Commit 553c3a4

Browse files
committed
Address review iteration 2: whatsnew entry + Py_ssize_t
- Add a 'faulthandler' entry to Doc/whatsnew/3.15.rst (per @ZeroIntensity). - Switch the max_threads parameters/fields and the nthreads loop counter in _Py_DumpTracebackThreads to Py_ssize_t (per @vstinner).
1 parent 4689f4e commit 553c3a4

6 files changed

Lines changed: 64 additions & 30 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,14 @@ difflib
894894
(Contributed by Jiahao Li in :gh:`134580`.)
895895

896896

897+
faulthandler
898+
------------
899+
900+
* Added the *max_threads* parameter in :func:`faulthandler.enable`,
901+
:func:`faulthandler.dump_traceback`, and :func:`faulthandler.dump_traceback_later`.
902+
(Contributed by Eric Froemling in :gh:`149085`.)
903+
904+
897905
functools
898906
---------
899907

Include/internal/pycore_faulthandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct _faulthandler_runtime_state {
5757
void *exc_handler;
5858
#endif
5959
int c_stack;
60-
unsigned int max_threads;
60+
Py_ssize_t max_threads;
6161
} fatal_error;
6262

6363
struct {
@@ -69,7 +69,7 @@ struct _faulthandler_runtime_state {
6969
int exit;
7070
char *header;
7171
size_t header_len;
72-
unsigned int max_threads;
72+
Py_ssize_t max_threads;
7373
/* The main thread always holds this lock. It is only released when
7474
faulthandler_thread() is interrupted before this thread exits, or at
7575
Python exit. */

Include/internal/pycore_traceback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern const char* _Py_DumpTracebackThreads(
6262
int fd,
6363
PyInterpreterState *interp,
6464
PyThreadState *current_tstate,
65-
unsigned int max_threads);
65+
Py_ssize_t max_threads);
6666

6767
/* Write a Unicode object into the file descriptor fd. Encode the string to
6868
ASCII using the backslashreplace error handler.

Modules/clinic/faulthandler.c.h

Lines changed: 41 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/faulthandler.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ get_thread_state(void)
186186
static void
187187
faulthandler_dump_traceback(int fd, int all_threads,
188188
PyInterpreterState *interp,
189-
unsigned int max_threads)
189+
Py_ssize_t max_threads)
190190
{
191191
static volatile int reentrant = 0;
192192

@@ -245,7 +245,7 @@ faulthandler.dump_traceback as faulthandler_dump_traceback_py
245245
file: object(py_default="sys.stderr") = NULL
246246
all_threads: bool = True
247247
*
248-
max_threads: unsigned_int(bitwise=False) = 100
248+
max_threads: Py_ssize_t = 100
249249
250250
Dump the traceback of the current thread into file.
251251
@@ -255,9 +255,8 @@ caps the number of threads dumped.
255255

256256
static PyObject *
257257
faulthandler_dump_traceback_py_impl(PyObject *module, PyObject *file,
258-
int all_threads,
259-
unsigned int max_threads)
260-
/*[clinic end generated code: output=e2b1d5c6bb275cb5 input=3f84b644d7b226a6]*/
258+
int all_threads, Py_ssize_t max_threads)
259+
/*[clinic end generated code: output=ee1bbc2668e56e77 input=38630eb40e641de6]*/
261260
{
262261
PyThreadState *tstate;
263262
const char *errmsg;
@@ -598,16 +597,16 @@ faulthandler.enable as faulthandler_py_enable
598597
all_threads: bool = True
599598
c_stack: bool = True
600599
*
601-
max_threads: unsigned_int(bitwise=False) = 100
600+
max_threads: Py_ssize_t = 100
602601
603602
Enable the fault handler.
604603
[clinic start generated code]*/
605604

606605
static PyObject *
607606
faulthandler_py_enable_impl(PyObject *module, PyObject *file,
608607
int all_threads, int c_stack,
609-
unsigned int max_threads)
610-
/*[clinic end generated code: output=5050dceeeeda70a4 input=e2607dfbb2c7f4ac]*/
608+
Py_ssize_t max_threads)
609+
/*[clinic end generated code: output=7ee655332317c47a input=e64759714f27b466]*/
611610
{
612611
int fd;
613612
PyThreadState *tstate;
@@ -790,7 +789,7 @@ faulthandler.dump_traceback_later
790789
file: object(py_default="sys.stderr") = NULL
791790
exit: bool = False
792791
*
793-
max_threads: unsigned_int(bitwise=False) = 100
792+
max_threads: Py_ssize_t = 100
794793
795794
Dump the traceback of all threads in timeout seconds.
796795
@@ -803,8 +802,8 @@ static PyObject *
803802
faulthandler_dump_traceback_later_impl(PyObject *module,
804803
PyObject *timeout_obj, int repeat,
805804
PyObject *file, int exit,
806-
unsigned int max_threads)
807-
/*[clinic end generated code: output=a0a1551011fe9f5f input=9aabfe7079a05dd3]*/
805+
Py_ssize_t max_threads)
806+
/*[clinic end generated code: output=543a0f3807113394 input=6836555ee157ddb4]*/
808807
{
809808
PyTime_t timeout, timeout_us;
810809
int fd;

Python/traceback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
12661266
const char* _Py_NO_SANITIZE_THREAD
12671267
_Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
12681268
PyThreadState *current_tstate,
1269-
unsigned int max_threads)
1269+
Py_ssize_t max_threads)
12701270
{
12711271
if (max_threads == 0) {
12721272
max_threads = DEFAULT_MAX_NTHREADS;
@@ -1315,7 +1315,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
13151315
return "unable to get the thread head state";
13161316

13171317
/* Dump the traceback of each thread */
1318-
unsigned int nthreads = 0;
1318+
Py_ssize_t nthreads = 0;
13191319
_Py_BEGIN_SUPPRESS_IPH
13201320
do
13211321
{

0 commit comments

Comments
 (0)