A very superficial remark: the boost/python.hpp include has to appear first, 
before any other includes (this goes back to a Python.h requirement, which has 
to appear before any system include).
I only give a small chance of fixing your problem, but it will also only take a 
few seconds to try out...
Ralf




>________________________________
>From: Nox 7Bitfaster <n...@7bitfaster.de>
>To: cplusplus-sig@python.org
>Sent: Friday, May 20, 2011 1:11 AM
>Subject: [C++-sig] boost.python call_method+thread => wrong exceptionhandling?
>
>
>Message
>
>
>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"
>usingboost::noncopyable;
>usingnamespaceboost::python;
>structInterface{
>PyObject *self;
>public:Interface(PyObject* s) : self(s) {}
>staticvoidThread(Interface* obj){
>obj->func();
>}
>voidstart_thread(void){
>boost::thread::thread(Interface::Thread, this);}
>voidfunc(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
>namespaceboost { namespacepython{
>template<> structhas_back_reference<Interface> : mpl::true_ {};}}
>BOOST_PYTHON_MODULE(test)
>{
>class_<Interface,noncopyable>("Interface")
>.def("start_thread", &Interface::start_thread)
>.def("func", &Interface::func);
>}
>intmain( intargc, char** argv ){
>PyImport_AppendInittab( "test", &inittest );Py_Initialize();
>PyEval_InitThreads();
>constchar* do_file1 = "import testnobj = test.Interface()nobj.func()"; 
>//raises the correct exception
>constchar* do_file2 = "import testnobj = 
>test.Interface()nobj.start_thread()nwhile 1: pass"; //raises no exception at 
>allPyRun_SimpleString(do_file2);
>return0;}
>
>_______________________________________________
>Cplusplus-sig mailing list
>Cplusplus-sig@python.org
>http://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to