@@ -348,14 +348,11 @@ way). This generally happens when a thread calls :c:func:`PyEval_RestoreThread`
348348or in between bytecode instructions, based on :func: `sys.setswitchinterval `.
349349
350350A new, internal field will be added to the ``PyThreadState `` structure that
351- determines if the thread is daemon. If the thread is daemon, then it will
352- hang during attachment as usual, but if it's not, then the interpreter will
353- let the thread attach and continue execution. On with-GIL builds, this again
354- means handing off the GIL to the thread. During finalization, the interpreter
351+ determines if the thread is daemon. Before finalization, the interpreter
355352will wait until all non-daemon threads call :c:func: `PyThreadState_Delete `.
356353
357- For backwards compatibility, all thread states created by existing APIs will
358- remain daemon by default.
354+ For backwards compatibility, all thread states created by existing APIs,
355+ including :c:func: ` PyGILState_Ensure `, will remain daemon by default.
359356
360357.. c :function :: int PyThreadState_SetDaemon (int is_daemon)
361358
@@ -396,8 +393,8 @@ A non-zero reference count prevents the interpreter from finalizing.
396393 This function is generally meant to be used in tandem with
397394 :c:func:`PyThreadState_Ensure`.
398395
399- The caller must have an :term:`attached thread state`, and cannot return
400- ``NULL``. Failures are always a fatal error.
396+ The caller must have an :term:`attached thread state`. This function
397+ cannot return ``NULL``. Failures are always a fatal error.
401398
402399.. c:function:: PyInterpreterState *PyInterpreterState_Lookup(int64_t interp_id)
403400
@@ -438,7 +435,7 @@ replace :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release`.
438435 there is a subsequent call to :c:func: `PyThreadState_Release ` that matches
439436 this one.
440437
441- The interpreter's *interp * reference count is decremented by one .
438+ The reference to the interpreter *interp * is stolen by this function .
442439 As such, *interp * should have been acquired by
443440 :c:func: `PyInterpreterState_Hold `.
444441
@@ -454,8 +451,9 @@ replace :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release`.
454451
455452.. c:function:: void PyThreadState_Release()
456453
457- Detach and destroy the :term:`attached thread state` set by
458- :c:func:`PyThreadState_Ensure`.
454+ Release the :term:`attached thread state` set by
455+ :c:func:`PyThreadState_Ensure`. Any thread state that was set prior
456+ to the original call to :c:func:`PyThreadState_Ensure` will be restored.
459457
460458 This function cannot fail, but may hang the thread if the
461459 attached thread state prior to the original :c:func:`!PyThreadState_Ensure`
@@ -728,7 +726,7 @@ deleted and cause use-after-free violations. :c:func:`PyInterpreterState_Hold`
728726fixes this issue anyway, but an interpreter ID does have the benefit of
729727requiring less magic in the implementation, but has several downsides:
730728
731- - Nearly all existing APIs already return a :c:type: `PyInterpreterState `
729+ - Nearly all existing interpreter APIs already return a :c:type: `PyInterpreterState `
732730 pointer, not an interpreter ID. Functions like
733731 :c:func: `PyThreadState_GetInterpreter ` would have to be accompanied by
734732 frustrating calls to :c:func: `PyInterpreterState_GetID `. There's also
0 commit comments