Using wxPython in embedded application

I've embedded Python/wxPython in an (MFC) application where I try to run
PyCrust for testing the integration. I'm using BOOST for the interface
between the application objects (MFC) and the Python system.

I'm having problems in that when launching the PyCrust dialog the second
time, the system runs into an exception. It seems to have something to
do with threads. (Launching a demo-dialog provided in the win32all
package seems to work).

I've made a small sample program with the problem. I've placed a
zip-file of the sample program on www.micon.no/Embed.zip. It is a
Visual C++ 6.0 project. I've used Python22 and Boost 1_30_0 for
linking.

The actual Python code executed is found in the PyExecutor::RunStmt
(class::method), and it only sets local variable (valx) to 'start' and
for every statement increments a counter which is set as a part of valx
so that I'm able to find out which statement triggered the exception.
It is always the statement which calls the main() function of
PyShellApp.

Hope someone can look at it.

Thanks for any help.

Nikolai

PS: The files PyThread.cpp and PyThread.h are empty. They contained
some experimental code that I have replaced with code found in MSDN (the
CThreadJob class).

Nikolai Kirsebom wrote:

I've embedded Python/wxPython in an (MFC) application where I try to run
PyCrust for testing the integration. I'm using BOOST for the interface
between the application objects (MFC) and the Python system.

I'm having problems in that when launching the PyCrust dialog the second
time, the system runs into an exception. It seems to have something to
do with threads. (Launching a demo-dialog provided in the win32all
package seems to work).

I don't have time to look in detail at your code right now, but perhaps a couple hints will help you.

1. You need to ensure that all wxPython code is run in the same thread, wxWindows will complain if this is not the case.

2. When calling wxPython code from C++ you need to aquire the Python Global Interpreter Lock, because the when the Python code calls back out to C++ wxWindows it will release the GIL and aquire it again when returning to Python. When you get control back then you need to release the GIL again.

3. See the wxPython/samples/embedded sample for more details of embedding wxPython in C++ apps, (although it shows how to do it from a wxWindows app, there should be some overlap for MFC apps...)

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!