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

Gennadiy Rozental rogeeff at gmail.com
Mon Jan 21 17:05:51 CET 2008


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();

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...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080121/2e6819f9/attachment.htm>


More information about the Cplusplus-sig mailing list