File tree 3 files changed +26
-6
lines changed
3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ include tox.ini
6
6
include *.rst
7
7
include src/_rtmidi.pyx
8
8
include src/_rtmidi.cpp
9
+ include src/pyinit.h
9
10
include src/rtmidi/RtMidi.cpp
10
11
include src/rtmidi/RtMidi.h
11
12
Original file line number Diff line number Diff line change @@ -131,13 +131,10 @@ else:
131
131
string_types = (str ,)
132
132
133
133
134
- # Init Python threads and GIL, because RtMidi calls Python from native threads.
135
- # See http://permalink.gmane.org/gmane.comp.python.cython.user/5837
136
- cdef extern from " Python.h" :
137
- void PyEval_InitThreads()
138
-
139
- PyEval_InitThreads()
134
+ cdef extern from " pyinit.h" :
135
+ void py_init()
140
136
137
+ py_init()
141
138
142
139
# Declarations for RtMidi C++ classes and their methods we use
143
140
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 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