10000 [3.12] Doc: C API: Move `tp_dealloc` paragraph to `tp_dealloc` sectio… · python/cpython@c3e705f · GitHub
[go: up one dir, main page]

Skip to content

Commit c3e705f

Browse files
[3.12] Doc: C API: Move tp_dealloc paragraph to tp_dealloc section (GH-125737) (#125799)
Doc: C API: Move `tp_dealloc` paragraph to `tp_dealloc` section (GH-125737) It looks like commit 43cf44d (gh-31501) accidentally moved the paragraph to the `tp_finalize` section when the intent was to move it to the `tp_dealloc` section (according to the commit message). (cherry picked from commit d880c83) Co-authored-by: Richard Hansen <rhansen@rhansen.org>
1 parent 2746ec4 commit c3e705f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Doc/c-api/typeobj.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,19 @@ and :c:data:`PyType_Type` effectively act as defaults.)
704704
Py_DECREF(tp);
705705
}
706706
707+
.. warning::
708+
709+
In a garbage collected Python, :c:member:`!tp_dealloc` may be called from
710+
any Python thread, not just the thread which created the object (if the
711+
object becomes part of a refcount cycle, that cycle might be collected by
712+
a garbage collection on any thread). This is not a problem for Python
713+
API calls, since the thread on which :c:member:`!tp_dealloc` is called
714+
will own the Global Interpreter Lock (GIL). However, if the object being
715+
destroyed in turn destroys objects from some other C or C++ library, care
716+
should be taken to ensure that destroying those objects on the thread
717+
which called :c:member:`!tp_dealloc` will not violate any assumptions of
718+
the library.
719+
707720

708721
**Inheritance:**
709722

@@ -2101,17 +2114,6 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21012114
PyErr_Restore(error_type, error_value, error_traceback);
21022115
}
21032116

2104-
Also, note that, in a garbage collected Python,
2105-
:c:member:`~PyTypeObject.tp_dealloc` may be called from
2106-
any Python thread, not just the thread which created the object (if the object
2107-
becomes part of a refcount cycle, that cycle might be collected by a garbage
2108-
collection on any thread). This is not a problem for Python API calls, since
2109-
the thread on which tp_dealloc is called will own the Global Interpreter Lock
2110-
(GIL). However, if the object being destroyed in turn destroys objects from some
2111-
other C or C++ library, care should be taken to ensure that destroying those
2112-
objects on the thread which called tp_dealloc will not violate any assumptions
2113-
of the library.
2114-
21152117
**Inheritance:**
21162118

21172119
This field is inherited by subtypes.

0 commit comments

Comments
 (0)
0