@@ -11,11 +11,6 @@ def setup_class(cls):
1111 cls .data = [3.1415 , 2.7183 , 1.4142 , 1.3807 , - 9.2848 ]
1212
1313 cppyy .cppdef ("""\
14- // as recommended by:
15- // https://docs.python.org/3/c-api/intro.html#include-files
16- #define PY_SSIZE_T_CLEAN
17- #include "Python.h"
18-
1914 namespace Workers {
2015 double calc(double d) { return d*42.; }
2116 }""" )
@@ -110,41 +105,19 @@ def test04_cpp_threading_with_exceptions(self):
110105 };
111106
112107 struct worker {
113- worker(consumer* c) : cons(c) {
114- // Get the main interpreter state state to spawn new thread states
115- PyThreadState* state = PyThreadState_Get();
116- interpreterState = state->interp;
117- }
108+ worker(consumer* c) : cons(c) { }
118109 ~worker() { wait(); }
119110
120111 void start() {
121112 t = std::thread([this] {
122113 int counter = 0;
123-
124- // Each thread needs a Python state object
125- // Instead of using the higher-level PyGILState_Ensure and
126- // PyGILState_Release functions, use the PyThreadState API
127- // directly so that we only need to create one single
128- // PyThreadState that can be restored and released in the
129- // "hot loop".
130- PyThreadState *pystate = PyThreadState_New(this->interpreterState);
131-
132114 while (counter++ < 10)
133115 try {
134- PyEval_RestoreThread(pystate);
135116 cons->process(counter);
136- PyEval_SaveThread();
137117 } catch (CPyCppyy::PyException& e) {
138118 err_msg = e.what();
139- PyEval_SaveThread();
140119 return;
141120 }
142-
143- PyEval_RestoreThread(pystate);
144- PyThreadState_Clear(pystate);
145- PyEval_SaveThread();
146-
147- PyThreadState_Delete(pystate);
148121 });
149122 }
150123
@@ -153,7 +126,6 @@ def test04_cpp_threading_with_exceptions(self):
153126 t.join();
154127 }
155128
156- PyInterpreterState* interpreterState = nullptr;
157129 std::thread t;
158130 consumer* cons = nullptr;
159131 std::string err_msg;
@@ -229,11 +201,7 @@ def test05_float2d_callback(self):
229201 for (int i = 0; i < channels; ++i)
230202 data[i] = new float[samples];
231203
232- // Set Python thread because we call back into Python
233- PyGILState_STATE gstate;
234- gstate = PyGILState_Ensure();
235204 p.process(data, channels, samples);
236- PyGILState_Release(gstate);
237205
238206 for (int i = 0; i < channels; ++i)
239207 delete[] data[i];
0 commit comments