From 922fb28b9f883b2705e35ef0d7a30e2df24f85e0 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sat, 18 Mar 2023 07:24:50 +0100 Subject: [PATCH 1/8] Update sys.rst Fixes https://github.com/python/cpython/issues/102249 --- Doc/library/sys.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index a53d4908783e15..c25772ac82c875 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -173,7 +173,11 @@ always available. Call ``func(*args)``, while tracing is enabled. The tracing state is saved, and restored afterwards. This is intended to be called from a debugger from - a checkpoint, to recursively debug some other code. + a checkpoint, to recursively debug or profile some other code. + + Tracing is suspended while calling a tracing function set by + :func:`settrace` or :func:`setprofile` to avoid infinite recursion. + :func:`call_tracing` enables explicit recursion of tracing function. .. data:: copyright From 621a637fb380125e033679bf8b2d663cce82c5be Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sat, 18 Mar 2023 07:28:14 +0100 Subject: [PATCH 2/8] Update sys.rst --- Doc/library/sys.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index c25772ac82c875..d8b8a6ca9027ee 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -174,10 +174,10 @@ always available. Call ``func(*args)``, while tracing is enabled. The tracing state is saved, and restored afterwards. This is intended to be called from a debugger from a checkpoint, to recursively debug or profile some other code. - + Tracing is suspended while calling a tracing function set by - :func:`settrace` or :func:`setprofile` to avoid infinite recursion. - :func:`call_tracing` enables explicit recursion of tracing function. + :func:`settrace` or :func:`setprofile` to avoid infinite recursion. + :func:`call_tracing` enables explicit recursion of tracing function. .. data:: copyright From b7d164d8d4308c8c764bfa63a7e422bc137a6fdb Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sat, 18 Mar 2023 17:41:41 +0100 Subject: [PATCH 3/8] Update Doc/library/sys.rst Co-authored-by: C.A.M. Gerlach --- Doc/library/sys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index d8b8a6ca9027ee..56561e12bdfe90 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -177,7 +177,7 @@ always available. Tracing is suspended while calling a tracing function set by :func:`settrace` or :func:`setprofile` to avoid infinite recursion. - :func:`call_tracing` enables explicit recursion of tracing function. + :func:`!call_tracing` enables explicit recursion of the tracing function. .. data:: copyright From 766ff10f90c316488f44f783fd6edaa834e3a927 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sat, 18 Mar 2023 17:53:38 +0100 Subject: [PATCH 4/8] Update sys.rst --- Doc/library/sys.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 56561e12bdfe90..444943e43f39a2 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1418,6 +1418,11 @@ always available. ``'c_exception'`` A C function has raised an exception. *arg* is the C function object. + + .. note:: + The same tracing mechanism is used for :func:`setprofile` than :func:`settrace`. + To trace calls with :func:`setprofile` inside a tracing function (e.g. in a + debugger breakpoint) see :func:`call_tracing`. .. function:: setrecursionlimit(limit) @@ -1478,6 +1483,10 @@ always available. If there is any error occurred in the trace function, it will be unset, just like ``settrace(None)`` is called. + + .. note:: + Tracing is disabled while calling the trace function (e.g. a function set by + :func:`settrace` or :func:`setprofile`). For recursive tracing see :func:`call_tracing`. The events have the following meaning: From 1ca8a1602d9e2dc663331ae2205651b3b91c6d7f Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sat, 18 Mar 2023 19:04:37 +0100 Subject: [PATCH 5/8] Update sys.rst --- Doc/library/sys.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 444943e43f39a2..fbddeb6fda505a 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1418,7 +1418,7 @@ always available. ``'c_exception'`` A C function has raised an exception. *arg* is the C function object. - + .. note:: The same tracing mechanism is used for :func:`setprofile` than :func:`settrace`. To trace calls with :func:`setprofile` inside a tracing function (e.g. in a @@ -1483,7 +1483,7 @@ always available. If there is any error occurred in the trace function, it will be unset, just like ``settrace(None)`` is called. - + .. note:: Tracing is disabled while calling the trace function (e.g. a function set by :func:`settrace` or :func:`setprofile`). For recursive tracing see :func:`call_tracing`. From 9806766659eccb3035aaefcce5e1d8423eeaf0cc Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sun, 19 Mar 2023 10:14:56 +0100 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: C.A.M. Gerlach --- Doc/library/sys.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index fbddeb6fda505a..2eb2895be80a8e 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1420,8 +1420,8 @@ always available. A C function has raised an exception. *arg* is the C function object. .. note:: - The same tracing mechanism is used for :func:`setprofile` than :func:`settrace`. - To trace calls with :func:`setprofile` inside a tracing function (e.g. in a + The same tracing mechanism is used for :func:`!setprofile` as :func:`settrace`. + To trace calls with :func:`!setprofile` inside a tracing function (e.g. in a debugger breakpoint) see :func:`call_tracing`. .. function:: setrecursionlimit(limit) @@ -1486,7 +1486,7 @@ always available. .. note:: Tracing is disabled while calling the trace function (e.g. a function set by - :func:`settrace` or :func:`setprofile`). For recursive tracing see :func:`call_tracing`. + :func:`!settrace`). For recursive tracing see :func:`call_tracing`. The events have the following meaning: From 349a5f99638385c8a63077d95e22b28a9c090026 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sun, 19 Mar 2023 10:16:50 +0100 Subject: [PATCH 7/8] Update sys.rst --- Doc/library/sys.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 2eb2895be80a8e..1fa61a86dcc6ff 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1396,7 +1396,12 @@ always available. ``'return'``, ``'c_call'``, ``'c_return'``, or ``'c_exception'``. *arg* depends on the event type. - .. audit-event:: sys.setprofile "" sys.setprofile +.. note:: + The same tracing mechanism is used for :func:`!setprofile` as :func:`settrace`. + To trace calls with :func:`!setprofile` inside a tracing function (e.g. in a + debugger breakpoint) see :func:`call_tracing`. + +.. audit-event:: sys.setprofile "" sys.setprofile The events have the following meaning: @@ -1419,11 +1424,6 @@ always available. ``'c_exception'`` A C function has raised an exception. *arg* is the C function object. - .. note:: - The same tracing mechanism is used for :func:`!setprofile` as :func:`settrace`. - To trace calls with :func:`!setprofile` inside a tracing function (e.g. in a - debugger breakpoint) see :func:`call_tracing`. - .. function:: setrecursionlimit(limit) Set the maximum depth of the Python interpreter stack to *limit*. This limit From a240a1ec894246f746cc223676857025f412a3f2 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Thu, 23 Mar 2023 05:53:36 +0100 Subject: [PATCH 8/8] comments --- Doc/library/sys.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 1fa61a86dcc6ff..d955ad2d65223d 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1391,18 +1391,16 @@ always available. its return value is not used, so it can simply return ``None``. Error in the profile function will cause itself unset. + .. note:: + The same tracing mechanism is used for :func:`!setprofile` as :func:`settrace`. + To trace calls with :func:`!setprofile` inside a tracing function + (e.g. in a debugger breakpoint), see :func:`call_tracing`. + Profile functions should have three arguments: *frame*, *event*, and *arg*. *frame* is the current stack frame. *event* is a string: ``'call'``, ``'return'``, ``'c_call'``, ``'c_return'``, or ``'c_exception'``. *arg* depends on the event type. -.. note:: - The same tracing mechanism is used for :func:`!setprofile` as :func:`settrace`. - To trace calls with :func:`!setprofile` inside a tracing function (e.g. in a - debugger breakpoint) see :func:`call_tracing`. - -.. audit-event:: sys.setprofile "" sys.setprofile - The events have the following meaning: ``'call'`` @@ -1424,6 +1422,9 @@ always available. ``'c_exception'`` A C function has raised an exception. *arg* is the C function object. + .. audit-event:: sys.setprofile "" sys.setprofile + + .. function:: setrecursionlimit(limit) Set the maximum depth of the Python interpreter stack to *limit*. This limit