Skip to content

Commit a00bfbb

Browse files
Apply suggestions from code review
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent f95bfc7 commit a00bfbb

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

Doc/c-api/interp-lifecycle.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ it possible to avoid these issues by temporarily preventing finalization:
608608
609609
.. seealso::
610610
611-
:pep:`788`
611+
:pep:`788` explains the design, motivation and rationale
612+
for these APIs.
612613
613614
.. c:type:: PyInterpreterGuard
614615
@@ -624,14 +625,19 @@ it possible to avoid these issues by temporarily preventing finalization:
624625
guards for that interpreter. This means that if you forget to close an
625626
interpreter guard, the process will **permanently hang** during
626627
finalization!
627-
628+
629+
Holding a guard for an interpreter is similar to holding a
630+
:term:`strong reference` to a Python object, except finalization does not happen
631+
automatically after all guards are released: it requires an explicit
632+
:c:func:`Py_EndInterpreter` call.
633+
628634
.. versionadded:: next
629635
630636
631637
.. c:function:: PyInterpreterGuard *PyInterpreterGuard_FromCurrent(void)
632638
633639
Create a finalization guard for the current interpreter. This will prevent
634-
finalization from occuring until the guard is closed.
640+
finalization until the guard is closed.
635641
636642
For example:
637643
@@ -764,8 +770,8 @@ deleted. This can be done using interpreter views.
764770
Failure indicates that the process is out of memory or that the main
765771
interpreter has finalized (or never existed).
766772
767-
Generally speaking, using this function is strongly discouraged, because
768-
it typically compromises subinterpreter support for a program. It exists
773+
Using this function in extension libraries is strongly discouraged, because
774+
it typically compromises the library's subinterpreter support. It exists
769775
for exceptional cases where there is no other option (such as when a native
770776
threading library doesn't provide a ``void *arg`` parameter that could be
771777
used to store a ``PyInterpreterGuard`` or ``PyInterpreterView`` pointer).

Doc/c-api/threads.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,10 @@ will hang the process during interpreter finalization (see
545545
:c:func:`PyGILState_GetThisThreadState`. If the caller has no attached thread
546546
state or it otherwise doesn't match, then this returns ``0``.
547547
548-
.. note::
549-
If the current Python process has ever created a subinterpreter, this
550-
function will *always* return ``1``.
548+
If the current Python process has ever created a subinterpreter, this
549+
function will *always* return ``1``.
550+
551+
This is mainly a helper/diagnostic function.
551552
552553
.. versionadded:: 3.4
553554

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ In the C API, :term:`interpreter finalization <interpreter shutdown>` can be
456456
problematic for many extensions, because :term:`attaching <attached thread
457457
state>` a thread state will permanently hang the thread, resulting in deadlocks
458458
and other spurious issues. Additionally, it has historically been impossible
459-
to atomically check whether an interpreter is alive, leading to crashes
459+
to safely check whether an interpreter is alive before using it, leading to crashes
460460
when a thread concurrently deletes an interpreter while another thread is
461461
trying to attach to it.
462462

0 commit comments

Comments
 (0)