GH-93503: Add thread-specific APIs to set profiling and tracing functions in the C-API (#93504)

* gh-93503: Add APIs to set profiling and tracing functions in all threads in the C-API

* Use a separate API

* Fix NEWS entry

* Add locks around the loop

* Document ignoring exceptions

* Use the new APIs in the sys module

* Update docs
This commit is contained in:
Pablo Galindo Salgado 2022-08-24 23:21:39 +01:00 committed by GitHub
parent 657976ad95
commit e34c82abeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 271 additions and 4 deletions

View file

@ -1774,6 +1774,18 @@ Python-level trace functions in previous versions.
The caller must hold the :term:`GIL`.
.. c:function:: void PyEval_SetProfileAllThreads(Py_tracefunc func, PyObject *obj)
Like :c:func:`PyEval_SetProfile` but sets the profile function in all running threads
belonging to the current interpreter instead of the setting it only on the current thread.
The caller must hold the :term:`GIL`.
As :c:func:`PyEval_SetProfile`, this function ignores any exceptions raised while
setting the profile functions in all threads.
.. versionadded:: 3.12
.. c:function:: void PyEval_SetTrace(Py_tracefunc func, PyObject *obj)
@ -1788,6 +1800,18 @@ Python-level trace functions in previous versions.
The caller must hold the :term:`GIL`.
.. c:function:: void PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *obj)
Like :c:func:`PyEval_SetTrace` but sets the tracing function in all running threads
belonging to the current interpreter instead of the setting it only on the current thread.
The caller must hold the :term:`GIL`.
As :c:func:`PyEval_SetTrace`, this function ignores any exceptions raised while
setting the trace functions in all threads.
.. versionadded:: 3.12
.. _advanced-debugging: