Skip to content

Commit 4abd4df

Browse files
committed
use PyGILState_Ensure and PyGILState_Release when calling into Python
1 parent fae2301 commit 4abd4df

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/PythonQtSignalReceiver.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ PyObject* PythonQtSignalTarget::call(PyObject* callable, const PythonQtMethodInf
6262
{
6363
Q_UNUSED(skipFirstArgumentOfMethodInfo)
6464

65+
PyGILState_STATE state = PyGILState_Ensure();
66+
6567
// Note: we check if the callable is a PyFunctionObject and has a fixed number of arguments
6668
// if that is the case, we only pass these arguments to python and skip the additional arguments from the signal
6769

@@ -138,6 +140,7 @@ PyObject* PythonQtSignalTarget::call(PyObject* callable, const PythonQtMethodInf
138140
Py_DECREF(pargs);
139141
}
140142

143+
PyGILState_Release(state);
141144
return result;
142145
}
143146

@@ -263,6 +266,8 @@ int PythonQtSignalReceiver::qt_metacall(QMetaObject::Call c, int id, void **argu
263266
QObject::qt_metacall(c, id, arguments);
264267
}
265268

269+
PyGILState_STATE state = PyGILState_Ensure();
270+
266271
Q_FOREACH(const PythonQtSignalTarget& t, _targets) {
267272
if (t.slotId() == id) {
268273
t.call(arguments);
@@ -277,6 +282,7 @@ int PythonQtSignalReceiver::qt_metacall(QMetaObject::Call c, int id, void **argu
277282
break;
278283
}
279284
}
285+
PyGILState_Release(state);
280286
return 0;
281287
}
282288

0 commit comments

Comments
 (0)