[C++-sig] python->c++ ->python

Gennadiy Rozental rogeeff at gmail.com
Mon Jan 21 16:38:54 CET 2008


Hi,

I've got a bit wierd usage scenario.

My C++ library A embeds python.
My library A can be loaded as a service using LoadLibrary/dlopen.
My library A can be unloaded using FreeLibrary.

Now there is another library B which is python extension. Library wants to 
use my library A on demand. For varios reasons it also wishes to unload my 
library A when it's done.

So here is an order of events:

python script test.py is started
pythons extension library B loaded.
Library B loads library A.
Library B unloads library A.
Library B loads library A again.
...

In theory this load/unload can happend any number of times. But here is the 
problem: it crashes for me. I've tried to pla with it for a bit. My latest 
test eliminates any logic from my library A, but following lines:

boost::python::dict d;
PyInitialize();
PyRun_String( "import sys\n", Py_file_input, d.ptr(), d.ptr() );

First time it works fine. Second time around it report an error like this:
"__import__ is unknown"

Any advice?

Thanks,

Gennadiy







More information about the Cplusplus-sig mailing list