Hi, Im currently working with boost.python and stumpled into a strang behavior. If I call a not existing method with call_method from the main thread everything works as excepted (exception is raised and handled in python) but if I call it from a seperate thread call_method does not raise a c++ runtime exception and the hole program crashes. Both cases can be switched by exchanging do_file1 with do_file2 in the testcode. Has someone an idea what I am doing wrong? Minimal testcase: http://codepad.org/7OMMBZGQ Tested with: boost 1.46.1 (statically linked) and python 2.6.5 under windows vista 32 bit Or as a plain code: #include <windows.h> #include "boost/thread.hpp" #include "boost/python.hpp" using boost::noncopyable; using namespace boost::python; struct Interface { PyObject *self; public: Interface(PyObject* s) : self(s) {} static void Thread(Interface* obj) { obj->func(); } void start_thread(void) { boost::thread::thread(Interface::Thread, this); } void func(void) { PyGILState_STATE gstate = PyGILState_Ensure(); call_method<void>(self, "not_existing_function_should_raise_an_exception"); PyGILState_Release(gstate); } }; // specialize has_back_reference for Entity namespace boost { namespace python { template <> struct has_back_reference<Interface> : mpl::true_ {}; }}
BOOST_PYTHON_MODULE(test) { class_<Interface,noncopyable>("Interface") .def("start_thread", &Interface::start_thread) .def("func", &Interface::func) ; } int main( int argc, char ** argv ) { PyImport_AppendInittab( "test", &inittest ); Py_Initialize(); PyEval_InitThreads(); const char* do_file1 = "import testnobj = test.Interface()nobj.func()"; //raises the correct exception const char* do_file2 = "import testnobj = test.Interface()nobj.start_thread()nwhile 1: pass"; //raises no exception at all PyRun_SimpleString(do_file2); return 0; }
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig