Module: kamailio Branch: master Commit: 0ffe157bc13e7759ae1cee63a584fad4ac9eb38f URL: https://github.com/kamailio/kamailio/commit/0ffe157bc13e7759ae1cee63a584fad4...
Author: S-P Chan shihping.chan@gmail.com Committer: space88man shihping.chan@gmail.com Date: 2024-11-05T11:01:08+08:00
app_python3: refactor GIL and thread state handling
* KEMI Python scripts that use Python threading for background jobs would observe that the Python threads are not running
This is due to not releasing the GIL when returning to the Kamailio event loop from KEMI calls
* The module was using PyGILState_Ensure / PyGILState_Release to ensure thread-correctness
It turns out that in this case these are the wrong functions to use
The main thread is already correct due to Py_Initialize(); the PyGILState_xxx functions are redundant
To release the GIL so Python threads run we use the macros Py_BLOCK_THREADS/Py_UNBLOCK_THREADS
Note: the PyGILState_XXX functions are for C-threads created by Python unaware libraries
---
Modified: src/modules/app_python3/app_python3_mod.c Modified: src/modules/app_python3/apy_kemi.h Modified: src/modules/app_python3/python_exec.c
---
Diff: https://github.com/kamailio/kamailio/commit/0ffe157bc13e7759ae1cee63a584fad4... Patch: https://github.com/kamailio/kamailio/commit/0ffe157bc13e7759ae1cee63a584fad4...