]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: remove deprecated PyEval_InitThreads() calls 66508/head
authorKefu Chai <k.chai@proxmox.com>
Thu, 4 Dec 2025 10:17:25 +0000 (18:17 +0800)
committerKefu Chai <k.chai@proxmox.com>
Thu, 4 Dec 2025 10:23:04 +0000 (18:23 +0800)
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 <k.chai@proxmox.com>
src/pybind/cephfs/cephfs.pyx
src/pybind/rados/rados.pyx
src/pybind/rgw/rgw.pyx

index 52e856facabf42cc12221fc8135fd7abcd85902c..dcd24682d0d90acb7a5fd56d3ebc689f325fad3e 100644 (file)
@@ -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:
index 27fa56e5f28793cceb8c05c92ab232e88b5beaa9..dc473e8fe500d8adaa26332efb7f2f176a41445f 100644 (file)
@@ -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
index 6da956e2d96f9b5ac75d448eec34bb9921dd58ea..84d5525404335dc89e5e9be4a85a20ed604ea0a0 100644 (file)
@@ -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: