From b8c412cb57509276824f63588bb494ef7af4d14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Heath=20Dutton=F0=9F=95=B4=EF=B8=8F?= Date: Thu, 1 Jan 2026 17:05:46 -0500 Subject: [PATCH] gh-69912: Document sys.getprofile() behavior with C profilers --- Doc/library/sys.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index a0621d4b0dbd09..8a34aabb9267d6 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1039,6 +1039,16 @@ always available. Unless explicitly noted otherwise, all variables are read-only Get the profiler function as set by :func:`setprofile`. + .. impl-detail:: + + The :func:`getprofile` function is intended only for implementing profilers + and similar tools. When a C profile function is in effect (for example, + one installed by ``cProfile``), the returned object is the internal + profiler object and not a callable suitable for passing to :func:`setprofile`. + As a result, saving and restoring the profiler state using + :func:`getprofile` and :func:`setprofile` may not work as expected when + C-based profilers are in use. + .. function:: gettrace()