Module: kamailio
Branch: master
Commit: effd74b61aff3fef27386a19035fe2df241650b5
URL:
https://github.com/kamailio/kamailio/commit/effd74b61aff3fef27386a19035fe2d…
Author: S-P Chan <shihping.chan(a)gmail.com>
Committer: space88man <shihping.chan(a)gmail.com>
Date: 2024-11-05T11:01:08+08:00
app_python3: initial support for free-threading Python
* free-threading build can be disabled by defining
-DKSR_PYTHON_DISABLE_FREETHREADING
* this has no effect if Python is a non-free-threading build
---
Modified: src/modules/app_python3/apy_kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/effd74b61aff3fef27386a19035fe2d…
Patch:
https://github.com/kamailio/kamailio/commit/effd74b61aff3fef27386a19035fe2d…
---
diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c
index 0c1ab535809..213a19e4703 100644
--- a/src/modules/app_python3/apy_kemi.c
+++ b/src/modules/app_python3/apy_kemi.c
@@ -530,7 +530,6 @@ static PyObject *init_KSR(void)
KSR_moduledef.m_methods = _sr_crt_KSRMethods;
_sr_apy_ksr_module = PyModule_Create(&KSR_moduledef);
-
Py_INCREF(_sr_apy_ksr_module);
m = 0;
@@ -538,6 +537,13 @@ static PyObject *init_KSR(void)
/* special sub-modules - x.modf() can have variable number of params */
_sr_apy_ksr_modules_list[m] = PyModule_Create(&KSR_x_moduledef);
PyModule_AddObject(_sr_apy_ksr_module, "x", _sr_apy_ksr_modules_list[m]);
+
+#if defined(Py_GIL_DISABLED) && !defined(KSR_PYTHON_DISABLE_FREETHREADING)
+#warning Python Free Threading build
+ PyUnstable_Module_SetGIL(_sr_apy_ksr_module, Py_MOD_GIL_NOT_USED);
+ PyUnstable_Module_SetGIL(_sr_apy_ksr_modules_list[m], Py_MOD_GIL_NOT_USED);
+#endif
+
Py_INCREF(_sr_apy_ksr_modules_list[m]);
m++;
@@ -579,6 +585,12 @@ static PyObject *init_KSR(void)
mmodule->m_size = -1;
_sr_apy_ksr_modules_list[m] = PyModule_Create(mmodule);
+
+#if defined(Py_GIL_DISABLED) && !defined(KSR_PYTHON_DISABLE_FREETHREADING)
+#warning Python Free Threading build
+ PyUnstable_Module_SetGIL(
+ _sr_apy_ksr_modules_list[m], Py_MOD_GIL_NOT_USED);
+#endif
PyModule_AddObject(_sr_apy_ksr_module, emods[k].kexp[0].mname.s,
_sr_apy_ksr_modules_list[m]);
Py_INCREF(_sr_apy_ksr_modules_list[m]);