diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-16 21:45:24 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-16 21:45:24 (GMT) |
commit | 861d9abfcf6a4a34790e4edc5e440a68534137e1 (patch) | |
tree | a4ea3ef14a2f0494743733b9db4079f27f5906ca /Include | |
parent | c36674a2c52ecb30e180b3bcced2b8c529cf72fb (diff) | |
download | cpython-861d9abfcf6a4a34790e4edc5e440a68534137e1.zip cpython-861d9abfcf6a4a34790e4edc5e440a68534137e1.tar.gz cpython-861d9abfcf6a4a34790e4edc5e440a68534137e1.tar.bz2 |
faulthandler now works in non-Python threads
Issue #26563:
* Add _PyGILState_GetInterpreterStateUnsafe() function: the single
PyInterpreterState used by this process' GILState implementation.
* Enhance _Py_DumpTracebackThreads() to retrieve the interpreter state from
autoInterpreterState in last resort. The function now accepts NULL for interp
and current_tstate parameters.
* test_faulthandler: fix a ResourceWarning when test is interrupted by CTRL+c
Diffstat (limited to 'Include')
-rw-r--r-- | Include/pystate.h | 16 | ||||
-rw-r--r-- | Include/traceback.h | 21 |
2 files changed, 29 insertions, 8 deletions
diff --git a/Include/pystate.h b/Include/pystate.h index 550c332..9423bc7 100644 --- a/Include/pystate.h +++ b/Include/pystate.h @@ -243,15 +243,23 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE); */ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void); -/* Helper/diagnostic function - return 1 if the current thread - * currently holds the GIL, 0 otherwise - */ #ifndef Py_LIMITED_API /* Issue #26558: Flag to disable PyGILState_Check(). - If set, PyGILState_Check() always return 1. */ + If set to non-zero, PyGILState_Check() always return 1. */ PyAPI_DATA(int) _PyGILState_check_enabled; +/* Helper/diagnostic function - return 1 if the current thread + currently holds the GIL, 0 otherwise. + + The function returns 1 if _PyGILState_check_enabled is non-zero. */ PyAPI_FUNC(int) PyGILState_Check(void); + +/* Unsafe function to get the single PyInterpreterState used by this process' + GILState implementation. + + Return NULL before _PyGILState_Init() is called and after _PyGILState_Fini() + is called. */ +PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void); #endif #endif /* #ifdef WITH_THREAD */ diff --git a/Include/traceback.h b/Include/traceback.h index 7c630e3..76e169a 100644 --- a/Include/traceback.h +++ b/Include/traceback.h @@ -53,19 +53,32 @@ PyAPI_DATA(void) _Py_DumpTraceback( PyThreadState *tstate); /* Write the traceback of all threads into the file 'fd'. current_thread can be - NULL. Return NULL on success, or an error message on error. + NULL. + + Return NULL on success, or an error message on error. This function is written for debug purpose only. It calls _Py_DumpTraceback() for each thread, and so has the same limitations. It only write the traceback of the first 100 threads: write "..." if there are more threads. + If current_tstate is NULL, the function tries to get the Python thread state + of the current thread. It is not an error if the function is unable to get + the current Python thread state. + + If interp is NULL, the function tries to get the interpreter state from + the current Python thread state, or from + _PyGILState_GetInterpreterStateUnsafe() in last resort. + + It is better to pass NULL to interp and current_tstate, the function tries + different options to retrieve these informations. + This function is signal safe. */ PyAPI_DATA(const char*) _Py_DumpTracebackThreads( - int fd, PyInterpreterState *interp, - PyThreadState *current_thread); - + int fd, + PyInterpreterState *interp, + PyThreadState *current_tstate); #ifndef Py_LIMITED_API |