Skip to content

Commit 93e25eb

Browse files
authored
Shift some things around
1 parent 326b31e commit 93e25eb

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

Doc/library/sys.monitoring.rst

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,23 @@ raise an exception unless it would be visible to other code.
243243

244244
To allow tools to monitor for real exceptions without slowing down generators
245245
and coroutines, the :monitoring-event:`STOP_ITERATION` event is provided.
246-
:monitoring-event:`STOP_ITERATION` can be locally disabled, unlike :monitoring-event:`RAISE`.
246+
:monitoring-event:`STOP_ITERATION` can be locally disabled, unlike
247+
:monitoring-event:`RAISE`.
247248

248-
Note that the :monitoring-event:`STOP_ITERATION` event and the :monitoring-event:`RAISE`
249-
event for a :exc:`StopIteration` exception are equivalent, and are treated as interchangeable
250-
when generating events. Implementations will favor :monitoring-event:`STOP_ITERATION` for
251-
performance reasons, but may generate a :monitoring-event:`RAISE` event with a :exc:`StopIteration`.
249+
Note that the :monitoring-event:`STOP_ITERATION` event and the
250+
:monitoring-event:`RAISE` event for a :exc:`StopIteration` exception are
251+
equivalent, and are treated as interchangeable when generating events.
252+
Implementations will favor :monitoring-event:`STOP_ITERATION` for performance
253+
reasons, but may generate a :monitoring-event:`RAISE` event with a
254+
:exc:`StopIteration`.
252255

253256
Turning events on and off
254257
-------------------------
255258

256259
In order to monitor an event, it must be turned on and a corresponding callback
257-
must be registered.
258-
Events can be turned on or off by setting the events either globally or
259-
for a particular code object.
260+
must be registered. Events can be turned on or off by setting the events either
261+
globally and/or for a particular code object. An event will trigger only once,
262+
even if it is turned on both globally and locally.
260263

261264

262265
Setting events globally
@@ -292,10 +295,6 @@ in Python (see :ref:`c-api-monitoring`).
292295
Activates all the local events for *code* which are set in *event_set*.
293296
Raises a :exc:`ValueError` if *tool_id* is not in use.
294297

295-
Events will only trigger once, regardless of whether the same event is
296-
activated globally as well as locally for a code object. Local activation
297-
also doesn't impact a global registration for the same event and vice-versa.
298-
299298

300299
Disabling events
301300
''''''''''''''''
@@ -333,12 +332,16 @@ Registering callback functions
333332
it is unregistered and returned.
334333
Otherwise :func:`register_callback` returns ``None``.
335334

336-
337335
Functions can be unregistered by calling
338336
``sys.monitoring.register_callback(tool_id, event, None)``.
339337

340338
Callback functions can be registered and unregistered at any time.
341339

340+
Callbacks are called only once regardless if the event is turned on both
341+
globally and locally. As such, if an event could be turned on for both global
342+
and local events by your code then the callback needs to be written to handle
343+
either trigger.
344+
342345
Registering or unregistering a callback function will generate a :func:`sys.audit` event.
343346

344347

0 commit comments

Comments
 (0)