Skip to content

Commit 80926b1

Browse files
Deploy preview for PR 1140 🛫
1 parent 38b041d commit 80926b1

File tree

560 files changed

+603
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

560 files changed

+603
-574
lines changed

pr-preview/pr-1140/_sources/c-api/init.rst.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,12 +2396,20 @@ per-object locks for :term:`free-threaded <free threading>` CPython. They are
23962396
intended to replace reliance on the :term:`global interpreter lock`, and are
23972397
no-ops in versions of Python with the global interpreter lock.
23982398
2399+
Critical sections are intended to be used for custom types implemented
2400+
in C-API extensions. They should generally not be used with built-in types like
2401+
:class:`list` and :class:`dict` because their public C-APIs
2402+
already use critical sections internally, with the notable
2403+
exception of :c:func:`PyDict_Next`, which requires critical section
2404+
to be acquired externally.
2405+
23992406
Critical sections avoid deadlocks by implicitly suspending active critical
2400-
sections and releasing the locks during calls to :c:func:`PyEval_SaveThread`.
2401-
When :c:func:`PyEval_RestoreThread` is called, the most recent critical section
2402-
is resumed, and its locks reacquired. This means the critical section API
2403-
provides weaker guarantees than traditional locks -- they are useful because
2404-
their behavior is similar to the :term:`GIL`.
2407+
sections, hence, they do not provide exclusive access such as provided by
2408+
traditional locks like :c:type:`PyMutex`. When a critical section is started,
2409+
the per-object lock for the object is acquired. If the code executed inside the
2410+
critical section calls C-API functions then it can suspend the critical section thereby
2411+
releasing the per-object lock, so other threads can acquire the per-object lock
2412+
for the same object.
24052413
24062414
The functions and structs used by the macros are exposed for cases
24072415
where C macros are not available. They should only be used as in the

pr-preview/pr-1140/_sources/extending/extending.rst.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,14 @@ references to all its items, so when item 1 is replaced, it has to dispose of
10841084
the original item 1. Now let's suppose the original item 1 was an instance of a
10851085
user-defined class, and let's further suppose that the class defined a
10861086
:meth:`!__del__` method. If this class instance has a reference count of 1,
1087-
disposing of it will call its :meth:`!__del__` method.
1087+
disposing of it will call its :meth:`!__del__` method. Internally,
1088+
:c:func:`PyList_SetItem` calls :c:func:`Py_DECREF` on the replaced item,
1089+
which invokes replaced item's corresponding
1090+
:c:member:`~PyTypeObject.tp_dealloc` function. During
1091+
deallocation, :c:member:`~PyTypeObject.tp_dealloc` calls
1092+
:c:member:`~PyTypeObject.tp_finalize`, which is mapped to the
1093+
:meth:`!__del__` method for class instances (see :pep:`442`). This entire
1094+
sequence happens synchronously within the :c:func:`PyList_SetItem` call.
10881095

10891096
Since it is written in Python, the :meth:`!__del__` method can execute arbitrary
10901097
Python code. Could it perhaps do something to invalidate the reference to

pr-preview/pr-1140/_sources/glossary.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Glossary
102102
statements.
103103

104104
asynchronous generator iterator
105-
An object created by a :term:`asynchronous generator` function.
105+
An object created by an :term:`asynchronous generator` function.
106106

107107
This is an :term:`asynchronous iterator` which when called using the
108108
:meth:`~object.__anext__` method returns an awaitable object which will execute

pr-preview/pr-1140/_static/glossary.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pr-preview/pr-1140/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ <h3>瀏覽</h3>
320320
<a href="https://www.python.org/psf/donations/">Please donate.</a>
321321
<br>
322322
<br>
323-
最後更新於 8月 26, 2025 (00:21 UTC)。
323+
最後更新於 8月 27, 2025 (00:21 UTC)。
324324

325325
<a href="/bugs.html">Found a bug</a>?
326326

pr-preview/pr-1140/bugs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ <h3>瀏覽</h3>
359359
<a href="https://www.python.org/psf/donations/">Please donate.</a>
360360
<br>
361361
<br>
362-
最後更新於 8月 26, 2025 (00:21 UTC)。
362+
最後更新於 8月 27, 2025 (00:21 UTC)。
363363

364364
<a href="/bugs.html">Found a bug</a>?
365365

pr-preview/pr-1140/c-api/abstract.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ <h3>瀏覽</h3>
329329
<a href="https://www.python.org/psf/donations/">Please donate.</a>
330330
<br>
331331
<br>
332-
最後更新於 8月 26, 2025 (00:21 UTC)。
332+
最後更新於 8月 27, 2025 (00:21 UTC)。
333333

334334
<a href="/bugs.html">Found a bug</a>?
335335

pr-preview/pr-1140/c-api/allocation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ <h3>瀏覽</h3>
346346
<a href="https://www.python.org/psf/donations/">Please donate.</a>
347347
<br>
348348
<br>
349-
最後更新於 8月 26, 2025 (00:21 UTC)。
349+
最後更新於 8月 27, 2025 (00:21 UTC)。
350350

351351
<a href="/bugs.html">Found a bug</a>?
352352

pr-preview/pr-1140/c-api/apiabiversion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ <h3>瀏覽</h3>
376376
<a href="https://www.python.org/psf/donations/">Please donate.</a>
377377
<br>
378378
<br>
379-
最後更新於 8月 26, 2025 (00:21 UTC)。
379+
最後更新於 8月 27, 2025 (00:21 UTC)。
380380

381381
<a href="/bugs.html">Found a bug</a>?
382382

pr-preview/pr-1140/c-api/arg.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ <h3>瀏覽</h3>
931931
<a href="https://www.python.org/psf/donations/">Please donate.</a>
932932
<br>
933933
<br>
934-
最後更新於 8月 26, 2025 (00:21 UTC)。
934+
最後更新於 8月 27, 2025 (00:21 UTC)。
935935

936936
<a href="/bugs.html">Found a bug</a>?
937937

0 commit comments

Comments
 (0)