提交 7de99aa9 authored 作者: Traun Leyden's avatar Traun Leyden

cleanup threadstate so that it removes the thread-local storage and cleans up…

cleanup threadstate so that it removes the thread-local storage and cleans up django database connections which are stored in thread-local.  fixes bug where it was leaking connections.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8193 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 9e5e1e7c
......@@ -176,11 +176,14 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
// or out .. thread state will currently be swapped in, and the SwapInThreadState
// will be null
if (swapin_tstate == NULL) {
// swap it out
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate mod_python.c swap-out! \n");
// PyEval_ReleaseThread(cur_tstate);
swapin_tstate = (void *) PyEval_SaveThread();
switch_channel_set_private(channel, "SwapInThreadState", (void *) swapin_tstate);
// clear out threadstate
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "clear threadstate \n");
// we know we are swapped in because swapin_tstate is NULL, and therefore we have the GIL, so
// it is safe to call PyThreadState_Get.
PyThreadState *cur_tstate = PyThreadState_Get();
PyThreadState_Clear(cur_tstate);
PyEval_ReleaseThread(cur_tstate);
PyThreadState_Delete(cur_tstate);
}
else {
// thread state is already swapped out, so, nothing for us to do
......@@ -189,7 +192,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
}
else {
// they ran python script from cmd line, behave a bit differently (untested)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate mod_python.c swap-out! \n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No session: Threadstate mod_python.c swap-out! \n");
PyEval_ReleaseThread(tstate);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论