diff --git a/src/python/mraapy.c b/src/python/mraapy.c index a3536f0..c1f8521 100644 --- a/src/python/mraapy.c +++ b/src/python/mraapy.c @@ -25,9 +25,13 @@ mraa_python_isr(void (*isr)(void*), void* isr_args) if (arglist == NULL) { syslog(LOG_ERR, "gpio: Py_BuildValue NULL"); } else { +#if PY_VERSION_HEX >= 0x03090000 + ret = PyObject_CallObject((PyObject*) isr, arglist); +#else ret = PyEval_CallObject((PyObject*) isr, arglist); +#endif if (ret == NULL) { - syslog(LOG_ERR, "gpio: PyEval_CallObject failed"); + syslog(LOG_ERR, "gpio: Python call failed"); PyObject *pvalue, *ptype, *ptraceback; PyObject *pvalue_pystr, *ptype_pystr, *ptraceback_pystr; PyObject *pvalue_ustr, *ptype_ustr, *ptraceback_ustr; diff --git a/src/python/mraapython.i b/src/python/mraapython.i index 521ef53..3a85d26 100644 --- a/src/python/mraapython.i +++ b/src/python/mraapython.i @@ -151,7 +151,13 @@ class Spi; // Initialise python threads, this allows use to grab the GIL when we are // required to do so Py_InitializeEx(0); +#if PY_VERSION_HEX < 0x03090000 + // PyEval_InitThreads() is deprecated since Python 3.9 and removed in Python 3.12 + // In Python 3.7+, the GIL is initialized automatically by Py_Initialize() + // Only call PyEval_InitThreads() for Python < 3.9 + // Reference: https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads PyEval_InitThreads(); +#endif // Add mraa_init() to the module initialisation process and set isr function mraa_result_t res = mraa_init(); if (res == MRAA_SUCCESS) {