[0.3.x] fixed : hang up at PyGILState_Ensure in different modules ( PySide for example )

git-svn-id: https://pykd.svn.codeplex.com/svn@86876 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2013-12-18 06:37:48 +00:00 committed by Mikhail I. Izmestev
parent ab7fa30e8e
commit 9884b06526

View File

@ -38,10 +38,10 @@ void PykdExt::setUp()
PyImport_AppendInittab("pykd", initpykd );
PyEval_InitThreads();
Py_Initialize();
PyEval_InitThreads();
python::object main = boost::python::import("__main__");
python::object main_namespace = main.attr("__dict__");
@ -172,14 +172,17 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
PyThreadState *localState = NULL;
PyThreadState *globalState = NULL;
PyGILState_STATE gilState;
PyEval_RestoreThread( m_pyState );
if ( !global )
{
globalState = PyThreadState_Swap( NULL );
globalState = Py_NewInterpreter();
localState = Py_NewInterpreter();
localState = PyEval_SaveThread();
gilState = PyGILState_Ensure();
python::object sys = python::import("sys");
@ -187,6 +190,12 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
sys.attr("stderr") = python::object( pykd::DbgOut() );
sys.attr("stdin") = python::object( pykd::DbgIn() );
}
else
{
m_pyState = PyEval_SaveThread();
gilState = PyGILState_Ensure();
}
if ( args.size() == 0 )
{
@ -214,7 +223,9 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
python::object global(main.attr("__dict__"));
try {
PykdInterruptWatch interruptWatch;
python::exec_file( scriptFileName.c_str(), global );
}
catch( python::error_already_set const & )
@ -223,30 +234,18 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
}
}
PyGILState_Release(gilState);
if ( !global )
{
PyInterpreterState *interpreter = localState->interp;
PyEval_RestoreThread( localState );
while( interpreter->tstate_head != NULL )
{
PyThreadState *threadState = (PyThreadState*)(interpreter->tstate_head);
PyThreadState_Clear(threadState);
PyThreadState_Swap( NULL );
PyThreadState_Delete(threadState);
}
PyInterpreterState_Clear(interpreter);
PyInterpreterState_Delete(interpreter);
Py_EndInterpreter(localState);
PyThreadState_Swap( globalState );
}
m_pyState = PyEval_SaveThread();
}
}
///////////////////////////////////////////////////////////////////////////////