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

Gustavo Carneiro gjcarneiro at gmail.com
Mon Jan 21 17:25:24 CET 2008


On 21/01/2008, Gennadiy Rozental <rogeeff at gmail.com> wrote:
>
>  For one thing I don;t beleive callig n PyInitializa multiple time isa
> proble. But in fact I;ve tried this test both with and without
> PyInitialize() and with
>
> If(!Py_IsInitialized() )
>    PyInitialize();
>

If the library that loads Python has to be unloaded, then maybe you should
call Py_Finalize() when the library is unloaded.  Or generally just fire a
debugger and figure out where/why it crashes...


result is the same.
>
> gennadiy
>
> "Gustavo Carneiro" <gjcarneiro at gmail.com> wrote in message
> news:a467ca4f0801210747l5af8c522s4240c256461e0ef at mail.gmail.com...
> 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...
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>


-- 
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/94bc10dc/attachment.htm>


More information about the Cplusplus-sig mailing list