Skip to content

Commit bd87768

Browse files
authored
Revert to prior init mechanism to support pypy (#202)
1 parent 801e9f1 commit bd87768

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/_rtmidi.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

src/py_init.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)