File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,10 +128,10 @@ __all__ = (
128128 ' get_compiled_api' , ' get_compiled_api_by_name' , ' get_rtmidi_version'
129129)
130130
131- cdef extern from " Python .h" :
132- void Py_Initialize ()
131+ cdef extern from " py_init .h" :
132+ void py_init ()
133133
134- Py_Initialize ()
134+ py_init ()
135135
136136# Declarations for RtMidi C++ classes and their methods we use
137137
Original file line number Diff line number Diff line change 1+ #include <Python.h>
2+ /*
3+ * This code initializes Python threads and GIL, because RtMidi calls Python
4+ * from native threads.
5+ *
6+ * See http://permalink.gmane.org/gmane.comp.python.cython.user/5837
7+ *
8+ * *PyEval_InitThreads* is a no-op since Python.37 and deprecated since
9+ * Python 3.6. Now *Py_Initialize* initializes the GIL.
10+ *
11+ * The calls are in this separate C file instead of in the main .pyx file so
12+ * that we can use pre-compiler conditionals and don't get a compiler
13+ * deprecation warning on Python 3.9+ for including *PyEval_InitThreads*.
14+ */
15+
16+ void py_init () {
17+ #if !defined(PYPY_VERSION ) and PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >= 7
18+ Py_Initialize ();
19+ #else
20+ PyEval_InitThreads ();
21+ #endif
22+ }
You can’t perform that action at this time.
0 commit comments