From f46d13c5e0847fdf6e8e8a4692fae687b1aac49a Mon Sep 17 00:00:00 2001 From: arrmansa <41120982+arrmansa@users.noreply.github.com> Date: Wed, 17 Jan 2024 01:44:06 +0530 Subject: [PATCH 1/2] Update ctypes.rst --- Doc/library/ctypes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index ef3a9a0f5898af4..a84ef8e84b87d2c 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1733,7 +1733,8 @@ 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. The function will acquire the GIL and use it like normal python + code 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: From 0bdb457f6384783becd748ab89e836d33ce89c57 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Mon, 19 Oct 2026 15:06:52 -0400 Subject: [PATCH 2/2] Improve wording. --- Doc/library/ctypes.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index a84ef8e84b87d2c..b9862b089a82af0 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1733,8 +1733,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 acquire the GIL and use it like normal python - code 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: