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

Gustavo Carneiro gjcarneiro at gmail.com
Mon Jan 21 16:47:42 CET 2008


On 21/01/2008, Gennadiy Rozental <rogeeff at gmail.com> wrote:
>
> 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?


Perhaps you are calling PyInitialize(); multiple times?  That would be a
mistake...

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080121/8667ed17/attachment.htm>


More information about the Cplusplus-sig mailing list