[C++-sig] python->c++ ->python
Gennadiy Rozental
rogeeff at gmail.com
Mon Jan 21 17:42:59 CET 2008
My library does both Initialize and Finalize in regular circumstances. When invoked from Python I disable both based on Py_IsInitialized() test. Since neither needs to be done in this case, right?
My library crashes somewhere during unloading second time in depth of system calls (stack is composed completely of python dll and system libs, no my library at all. But as I said in minimal example it doesn't crash it just throw an exception indicating interpreter is corrupted.
Gennadiy
"Gustavo Carneiro" <gjcarneiro at gmail.com> wrote in message news:a467ca4f0801210825p6c070dabr282a9300a4b6dd2d at mail.gmail.com...
On 21/01/2008, Gennadiy Rozental <rogeeff at gmail.com> wrote:
For one thing I don't believe calling PyInitialize multiple time is a problem. 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.
Gennady
"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 weird 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 various 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 happened any number of times. But here is the
problem: it crashes for me. I've tried to play 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
------------------------------------------------------------------------------
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080121/a11a9f0b/attachment.htm>
More information about the Cplusplus-sig
mailing list