Skip to content

Commit aa4dd4e

Browse files
miss-islingtonbrettcannonStanFromIreland
authored
[3.13] Document that returning sys.monitoring.DISABLE in response to a global event raises ValueError (GH-140726) (GH-141015)
Document that returning `sys.monitoring.DISABLE` in response to a global event raises `ValueError` (GH-140726) (cherry picked from commit 8a7dbb7) Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]>
1 parent 5614605 commit aa4dd4e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Doc/library/sys.monitoring.rst

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,17 @@ by another event:
198198

199199
The :monitoring-event:`C_RETURN` and :monitoring-event:`C_RAISE` events
200200
are controlled by the :monitoring-event:`CALL` event.
201-
:monitoring-event:`C_RETURN` and :monitoring-event:`C_RAISE` events will only be seen if the
202-
corresponding :monitoring-event:`CALL` event is being monitored.
201+
:monitoring-event:`C_RETURN` and :monitoring-event:`C_RAISE` events will only be
202+
seen if the corresponding :monitoring-event:`CALL` event is being monitored.
203+
204+
205+
.. _monitoring-event-global:
203206

204207
Other events
205208
''''''''''''
206209

207210
Other events are not necessarily tied to a specific location in the
208-
program and cannot be individually disabled.
211+
program and cannot be individually disabled via :data:`DISABLE`.
209212

210213
The other events that can be monitored are:
211214

@@ -264,12 +267,13 @@ in Python (see :ref:`c-api-monitoring`).
264267

265268
.. function:: get_local_events(tool_id: int, code: CodeType, /) -> int
266269

267-
Returns all the local events for *code*
270+
Returns all the :ref:`local events <monitoring-event-local>` for *code*
268271

269272
.. function:: set_local_events(tool_id: int, code: CodeType, event_set: int, /) -> None
270273

271-
Activates all the local events for *code* which are set in *event_set*.
272-
Raises a :exc:`ValueError` if *tool_id* is not in use.
274+
Activates all the :ref:`local events <monitoring-event-local>` for *code*
275+
which are set in *event_set*. Raises a :exc:`ValueError` if *tool_id* is not
276+
in use.
273277

274278
Local events add to global events, but do not mask them.
275279
In other words, all global events will trigger for a code object,
@@ -284,15 +288,21 @@ Disabling events
284288
A special value that can be returned from a callback function to disable
285289
events for the current code location.
286290

287-
Local events can be disabled for a specific code location by returning
288-
:data:`sys.monitoring.DISABLE` from a callback function. This does not change
289-
which events are set, or any other code locations for the same event.
291+
:ref:`Local events <monitoring-event-local>` can be disabled for a specific code
292+
location by returning :data:`sys.monitoring.DISABLE` from a callback function.
293+
This does not change which events are set, or any other code locations for the
294+
same event.
290295

291296
Disabling events for specific locations is very important for high
292297
performance monitoring. For example, a program can be run under a
293298
debugger with no overhead if the debugger disables all monitoring
294299
except for a few breakpoints.
295300

301+
If :data:`DISABLE` is returned by a callback for a
302+
:ref:`global event <monitoring-event-global>`, :exc:`ValueError` will be raised
303+
by the interpreter in a non-specific location (that is, no traceback will be
304+
provided).
305+
296306
.. function:: restart_events() -> None
297307

298308
Enable all the events that were disabled by :data:`sys.monitoring.DISABLE`

0 commit comments

Comments
 (0)