From: Kefu Chai Date: Thu, 4 Dec 2025 10:17:25 +0000 (+0800) Subject: pybind: remove deprecated PyEval_InitThreads() calls X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f261379edcd9128aa5c120d9eca269341b632f68;p=ceph.git pybind: remove deprecated PyEval_InitThreads() calls Remove all calls to PyEval_InitThreads(), which has been deprecated since Python 3.9 and generates compiler warnings on Python 3.13+. Background: ----------- PyEval_InitThreads() was used to initialize Python's GIL (Global Interpreter Lock) and threading support. In Python 3.7+, the GIL is automatically initialized, making this function a no-op. From Python 3.9 source (Python/ceval.c:315-318): void PyEval_InitThreads(void) { /* Do nothing */ } The function was officially deprecated in Python 3.9: https://docs.python.org/3/whatsnew/3.9.html "Deprecated: PyEval_InitThreads() and PyEval_ThreadsInitialized() are now deprecated and will be removed in Python 3.13." As of Python 3.13, calling this function produces deprecation warnings: warning: 'PyEval_InitThreads' is deprecated [-Wdeprecated-declarations] Rationale: ---------- Ceph enforces a minimum Python version of 3.9 (CMakeLists.txt:630): if(Python3_VERSION VERSION_LESS 3.9) message(FATAL_ERROR "... please use Python 3.9 and up") Since we require Python 3.9+, and PyEval_InitThreads() is a no-op in Python 3.9+, these calls serve no purpose and can be safely removed. Changes: -------- - Removed PyEval_InitThreads() declaration from cdef extern blocks - Removed PyEval_InitThreads() calls from __init__/__cinit__ methods Affected files: - src/pybind/rados/rados.pyx (Rados.__init__) - src/pybind/rgw/rgw.pyx (LibRGWFS.__cinit__) - src/pybind/cephfs/cephfs.pyx (LibCephFS.__cinit__) References: - Python 3.9 source: https://github.com/python/cpython/blob/3.9/Python/ceval.c#L315-L318 - Python 3.9 What's New: https://docs.python.org/3/whatsnew/3.9.html - Python 3.13 deprecation: https://docs.python.org/3.13/c-api/init.html#c.PyEval_InitThreads Signed-off-by: Kefu Chai --- diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 52e856facabf..dcd24682d0d9 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -118,7 +118,6 @@ cdef extern from "Python.h": PyObject *PyBytes_FromStringAndSize(char *v, Py_ssize_t len) except NULL char* PyBytes_AsString(PyObject *string) except NULL int _PyBytes_Resize(PyObject **string, Py_ssize_t newsize) except -1 - void PyEval_InitThreads() cdef void completion_callback(int rc, const void* out, size_t outlen, const void* outs, size_t outslen, void* ud) nogil: # This GIL awkwardness is due to incompatible types with function pointers defined with mds_command2: @@ -513,7 +512,6 @@ cdef class LibCephFS(object): :auth_id str opt: the id used to authenticate the client entity :rados_inst Rados opt: a rados.Rados instance """ - PyEval_InitThreads() self.state = "uninitialized" if rados_inst is not None: if auth_id is not None or conffile is not None or conf is not None: diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 27fa56e5f287..dc473e8fe500 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -39,7 +39,6 @@ cdef extern from "Python.h": PyObject *PyBytes_FromStringAndSize(char *v, Py_ssize_t len) except NULL char* PyBytes_AsString(PyObject *string) except NULL int _PyBytes_Resize(PyObject **string, Py_ssize_t newsize) except -1 - void PyEval_InitThreads() LIBRADOS_OP_FLAG_EXCL = _LIBRADOS_OP_FLAG_EXCL LIBRADOS_OP_FLAG_FAILOK = _LIBRADOS_OP_FLAG_FAILOK @@ -394,7 +393,6 @@ cdef class Rados(object): # NOTE(sileht): attributes declared in .pyd def __init__(self, *args, **kwargs): - PyEval_InitThreads() self.__setup(*args, **kwargs) NO_CONF_FILE = -1 diff --git a/src/pybind/rgw/rgw.pyx b/src/pybind/rgw/rgw.pyx index 6da956e2d96f..84d552540433 100644 --- a/src/pybind/rgw/rgw.pyx +++ b/src/pybind/rgw/rgw.pyx @@ -28,7 +28,6 @@ cdef extern from "Python.h": PyObject *PyBytes_FromStringAndSize(char *v, Py_ssize_t len) except NULL char* PyBytes_AsString(PyObject *string) except NULL int _PyBytes_Resize(PyObject **string, Py_ssize_t newsize) except -1 - void PyEval_InitThreads() class Error(Exception): @@ -195,7 +194,6 @@ cdef class LibRGWFS(object): "RGWFS object in state %s." % (self.state)) def __cinit__(self, uid, key, secret): - PyEval_InitThreads() self.state = "umounted" ret = librgw_create(&self.cluster, 0, NULL) if ret != 0: