@@ -172,16 +172,27 @@ bound into a function.
172
172
before the destruction of *co* takes place, so the prior state of *co*
173
173
can be inspected.
174
174
175
+ If *event* is ``PY_CODE_EVENT_DESTROY``, taking a reference in the callback
176
+ to the about-to-be-destroyed code object will resurrect it and prevent it
177
+ from being freed at this time. When the resurrected object is destroyed
178
+ later, any watcher callbacks active at that time will be called again.
179
+
175
180
Users of this API should not rely on internal runtime implementation
176
181
details. Such details may include, but are not limited to, the exact
177
182
order and timing of creation and destruction of code objects. While
178
183
changes in these details may result in differences observable by watchers
179
184
(including whether a callback is invoked or not), it does not change
180
185
the semantics of the Python code being executed.
181
186
182
- If the callback returns with an exception set, it must return ``-1``; this
183
- exception will be printed as an unraisable exception using
184
- :c:func: `PyErr_WriteUnraisable `. Otherwise it should return ``0 ``.
187
+ If the callback sets an exception, it must return ``-1``; this exception will
188
+ be printed as an unraisable exception using :c:func: `PyErr_WriteUnraisable `.
189
+ Otherwise it should return ``0 ``.
190
+
191
+ There may already be a pending exception set on entry to the callback. In
192
+ this case, the callback should return ``0 `` with the same exception still
193
+ set. This means the callback may not call any other API that can set an
194
+ exception unless it saves and clears the exception state first, and restores
195
+ it before returning.
185
196
186
197
.. versionadded :: 3.12
187
198
0 commit comments