Boost.Python 'Fatal Error'

Hello there, I've just started using Boost.Python, and find it absolutely invaluable. For the moment, my main task is embedding the python interpreter within an application of mine, and I have successfully built a small application that can load a module, execute a Python function and then collect the result. The next logical step was to extend the Python script somewhat into objects. I wrote some extra code in the script which I checked with the command line interpreter and verified to work. Before changing the C++ code to actually /use/ these new objects, I decided to just see what would happen if I kept exactly the same C++ code but with the new Python script (which still contains the function used for the last example). It ran fine - producing the correct output - but then exited abruptly with the following message: "Fatal Python error: PyThreadState_Get: no current thread". The changes to the original script file were the addition of two new classes - OptionsGUI and Button - and, oddly, commenting out Button makes the program work again (I say oddly because it's simply a class with a constructor, nothing more). Evidently I'm using the library incorrectly, and have searched through the documentation for things I might have done wrong but alas, I do find it rather daunting. I also noticed that my code is quite different from examples - is this a correct way to be doing things? And yes, at present, I'm not doing any exception or error handling - I'm a little unclear on it but I'm sure I will be able to do it given time :) For those wishing to look at the source, I have put the two files - EmbeddedPythonFunc.cpp and script2.py - in my webspace to prevent everyone having to download them as attachments. They are available at the following addresses: http://kutsurogu.pwp.blueyonder.co.uk/EmbeddedPythonFunc.cpp http://kutsurogu.pwp.blueyonder.co.uk/script2.py (incidentally, I didn't include stdafx.h because it simply includes iostream, tchar.h and boost/python.hpp). I hope I have sent my help request to the right place! Apologies if I have not. Thank you in advance, Ed Fear

Ed Fear
For those wishing to look at the source, I have put the two files - EmbeddedPythonFunc.cpp and script2.py - in my webspace to prevent everyone having to download them as attachments. They are available at the following addresses:
http://kutsurogu.pwp.blueyonder.co.uk/EmbeddedPythonFunc.cpp http://kutsurogu.pwp.blueyonder.co.uk/script2.py
(incidentally, I didn't include stdafx.h because it simply includes iostream, tchar.h and boost/python.hpp).
I hope I have sent my help request to the right place!
The most-right place is http://www.boost.org/more/mailing_lists.htm#cplussig. Please ask there if you have more questions. Boost.Python is not compatible with PyFinalize (see http://www.boost.org/libs/python/todo.html#pyfinalize-safety). Try just not calling it. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
Ed Fear