@@ -253,6 +253,13 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
253253 returned immediately.
254254 Otherwise, return zero.
255255
256+ The garbage collector can call :c:member: `~PyTypeObject.tp_traverse ` more
257+ than once for the same object during a collection. If the object's
258+ references do not change, each traversal must visit the same references.
259+ In particular, do not skip a reference because a lock is busy.
260+ If one traversal visits a reference and a later traversal skips it, the
261+ collector can clear an object that is still reachable.
262+
256263 A typical :c:member: `!tp_traverse ` function calls the :c:func: `Py_VISIT `
257264 convenience macro on each of the instance's members that are Python
258265 objects that the instance owns.
@@ -318,14 +325,6 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
318325 For a list of safe functions, see a
319326 :ref:`separate section <duringgc-functions>` below.
320327
321- If an error occurs during traversal, ignore it and return 0.
322- If ``tp_traverse`` fails to visit some strong references, garbage reference
323- cycles involving the skipped references will not be reliably broken,
324- but correctness won't be affected.
325- For example, if traversal requires a lock that cannot be acquired promptly,
326- skip the traversal.
327- The garbage collector will visit your object again in a future pass.
328-
329328 .. note::
330329
331330 The :c:func:`Py_VISIT` call may be skipped for those members that provably
0 commit comments