From 3dcd756f297fe66c7a996624fb3d9f1b6f32d6db Mon Sep 17 00:00:00 2001 From: arrmansa <41120982+arrmansa@users.noreply.github.com> Date: Tue, 20 Oct 2026 00:50:07 +0530 Subject: [PATCH] gh-114150: Clarify that `ctypes.PYFUNCTYPE` can release the GIL during the call (GH-114151) (cherry picked from commit d42178a811d05c0ad3623034a12ff018a07e7ec7) Co-authored-by: arrmansa <41120982+arrmansa@users.noreply.github.com> Co-authored-by: Peter Bierma --- Doc/library/ctypes.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index fb74e7f3ee37192..f0a934b15ceb2ab 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1968,7 +1968,11 @@ See :ref:`ctypes-callback-functions` for examples. .. function:: PYFUNCTYPE(restype, *argtypes) The returned function prototype creates functions that use the Python calling - convention. The function will *not* release the GIL during the call. + convention. Unlike :func:`CFUNCTYPE` and :func:`WINFUNCTYPE`, ctypes does + *not* release the GIL before calling the foreign function, so the function + may safely use the Python C API. Note that this does not prevent the GIL + from being released *during* the call. + Function prototypes created by these factory functions can be instantiated in different ways, depending on the type and number of the parameters in the call: