mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[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:
parent
ab7fa30e8e
commit
9884b06526
@ -38,10 +38,10 @@ void PykdExt::setUp()
|
|||||||
|
|
||||||
PyImport_AppendInittab("pykd", initpykd );
|
PyImport_AppendInittab("pykd", initpykd );
|
||||||
|
|
||||||
PyEval_InitThreads();
|
|
||||||
|
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
|
|
||||||
|
PyEval_InitThreads();
|
||||||
|
|
||||||
python::object main = boost::python::import("__main__");
|
python::object main = boost::python::import("__main__");
|
||||||
|
|
||||||
python::object main_namespace = main.attr("__dict__");
|
python::object main_namespace = main.attr("__dict__");
|
||||||
@ -172,14 +172,17 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
|
|||||||
|
|
||||||
PyThreadState *localState = NULL;
|
PyThreadState *localState = NULL;
|
||||||
PyThreadState *globalState = NULL;
|
PyThreadState *globalState = NULL;
|
||||||
|
PyGILState_STATE gilState;
|
||||||
|
|
||||||
PyEval_RestoreThread( m_pyState );
|
PyEval_RestoreThread( m_pyState );
|
||||||
|
|
||||||
if ( !global )
|
if ( !global )
|
||||||
{
|
{
|
||||||
globalState = PyThreadState_Swap( NULL );
|
globalState = Py_NewInterpreter();
|
||||||
|
|
||||||
localState = Py_NewInterpreter();
|
localState = PyEval_SaveThread();
|
||||||
|
|
||||||
|
gilState = PyGILState_Ensure();
|
||||||
|
|
||||||
python::object sys = python::import("sys");
|
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("stderr") = python::object( pykd::DbgOut() );
|
||||||
sys.attr("stdin") = python::object( pykd::DbgIn() );
|
sys.attr("stdin") = python::object( pykd::DbgIn() );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pyState = PyEval_SaveThread();
|
||||||
|
|
||||||
|
gilState = PyGILState_Ensure();
|
||||||
|
}
|
||||||
|
|
||||||
if ( args.size() == 0 )
|
if ( args.size() == 0 )
|
||||||
{
|
{
|
||||||
@ -214,7 +223,9 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
|
|||||||
python::object global(main.attr("__dict__"));
|
python::object global(main.attr("__dict__"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
PykdInterruptWatch interruptWatch;
|
PykdInterruptWatch interruptWatch;
|
||||||
|
|
||||||
python::exec_file( scriptFileName.c_str(), global );
|
python::exec_file( scriptFileName.c_str(), global );
|
||||||
}
|
}
|
||||||
catch( python::error_already_set const & )
|
catch( python::error_already_set const & )
|
||||||
@ -223,30 +234,18 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyGILState_Release(gilState);
|
||||||
|
|
||||||
if ( !global )
|
if ( !global )
|
||||||
{
|
{
|
||||||
PyInterpreterState *interpreter = localState->interp;
|
PyEval_RestoreThread( localState );
|
||||||
|
|
||||||
while( interpreter->tstate_head != NULL )
|
Py_EndInterpreter(localState);
|
||||||
{
|
|
||||||
PyThreadState *threadState = (PyThreadState*)(interpreter->tstate_head);
|
|
||||||
|
|
||||||
PyThreadState_Clear(threadState);
|
|
||||||
|
|
||||||
PyThreadState_Swap( NULL );
|
|
||||||
|
|
||||||
PyThreadState_Delete(threadState);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyInterpreterState_Clear(interpreter);
|
|
||||||
|
|
||||||
PyInterpreterState_Delete(interpreter);
|
|
||||||
|
|
||||||
PyThreadState_Swap( globalState );
|
PyThreadState_Swap( globalState );
|
||||||
|
|
||||||
|
m_pyState = PyEval_SaveThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pyState = PyEval_SaveThread();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user