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

Skip to content

Commit ff4cd88

Browse files
author
Victor Stinner
committed
faulthandler: fix compilating without threads
1 parent 44e31ba commit ff4cd88

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_faulthandler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import tempfile
99
import unittest
1010

11+
try:
12+
import threading
13+
HAVE_THREADS = True
14+
except ImportError:
15+
HAVE_THREADS = False
16+
1117
TIMEOUT = 0.5
1218

1319
try:
@@ -279,6 +285,7 @@ def test_dump_traceback_file(self):
279285
with temporary_filename() as filename:
280286
self.check_dump_traceback(filename)
281287

288+
@unittest.skipIf(not HAVE_THREADS, 'need threads')
282289
def check_dump_traceback_threads(self, filename):
283290
"""
284291
Call explicitly dump_traceback(all_threads=True) and check the output.

Modules/faulthandler.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ faulthandler_fatal_error(int signum)
250250
PUTS(fd, handler->name);
251251
PUTS(fd, "\n\n");
252252

253+
#ifdef WITH_THREAD
253254
/* SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals and
254255
so are delivered to the thread that caused the fault. Get the Python
255256
thread state of the current thread.
@@ -259,6 +260,9 @@ faulthandler_fatal_error(int signum)
259260
used. Read the thread local storage (TLS) instead: call
260261
PyGILState_GetThisThreadState(). */
261262
tstate = PyGILState_GetThisThreadState();
263+
#else
264+
tstate = PyThreadState_Get();
265+
#endif
262266
if (tstate == NULL)
263267
return;
264268

@@ -540,10 +544,14 @@ faulthandler_user(int signum)
540544
if (!user->enabled)
541545
return;
542546

547+
#ifdef WITH_THREAD
543548
/* PyThreadState_Get() doesn't give the state of the current thread if
544549
the thread doesn't hold the GIL. Read the thread local storage (TLS)
545550
instead: call PyGILState_GetThisThreadState(). */
546551
tstate = PyGILState_GetThisThreadState();
552+
#else
553+
tstate = PyThreadState_Get();
554+
#endif
547555

548556
if (user->all_threads)
549557
_Py_DumpTracebackThreads(user->fd, user->interp, tstate);

0 commit comments

Comments
 (0)