[PyKDE] Embedding sip

Christian Bird chris.bird at lineo.com
Wed Mar 7 16:27:47 GMT 2001


Hi Phil,

I've got a question for you about the sip library.  We're embedding python running
pyqt into a C++ application
(wierd, I know, but python allows for a lot of flexibilty and coupled with Qt, it's
great!)  We're running into problems
with the sip library and hope that you might have a suggestion.  We stop and
restart the python interpreter many
times throughout the our program and after the first time, when we start up the
interpreter, siplib has problems.
It complains that:

RuntimeError: SIP - module "qt" implements QObject but it has already been
implemented

I'm guessing that since sip is implemented in C and not python that maybe some
things are left laying around
when we stop the python interpreter and when it starts up again and imports qt, sip
notices some remnants
from the last time it was used.  I would guess that we just need to make sure that
everything is cleaned up
in sip when the embedded python interpreter closes.  Do you have any ideas of
things we could try to get this
working?  I've included a small test program that demonstrates the problem.  Thanks
for your help.

Christiain Bird
chris.bird at lineo.com

> The attached tarball has a very simple test program which
> demonstrates the problem.
>
> Here's qttest.c
> ////////////////////////////////////////////////////
> // pytest.c - brief program to show embedding and extending python
> //
> #include <stdio.h>
> #include <string.h>
>
> #include <Python.h>
>
> int main(int argc, char **argv)
> {
>         char *progname;
>         char *string;
>         long a;
>
>         // now initialize the interpreter
>         Py_Initialize();
>
>         ///////////////////////////////////////////////
>         // do a very simple test
>         printf("test #1 - simple assignment and print\n");
>         string = "a=5+2\nprint 'a=',a";
>         //printf("running string=\"%s\"", string);
>         PyRun_SimpleString(string);
>
>         ///////////////////////////////////////////////
>         // try to import qt
>         printf("test #9.1 - importing qt\n");
>         string = "import qt\n";
>         PyRun_SimpleString(string);
>
>         ///////////////////////////////////////////////
>         Py_Finalize();
>
>         // now re-initialize the interpreter
>         Py_Initialize();
>
>         ///////////////////////////////////////////////
>         // try to import qt
>         printf("test #9.2 - try re-importing qt\n");
>         string = "import qt\n";
>         PyRun_SimpleString(string);
>
>         ///////////////////////////////////////////////
>         Py_Finalize();
> }
>
> I get the following result from running the code:
>
> ########################## (without PYTHONVERBOSE)
> test #1 - simple assignment and print
> a= 7
> test #9.1 - importing qt
> test #9.2 - try re-importing qt
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
>   File "/opt/Embedix/usr/lib/python2.0/site-packages/qt.py", line 1173, in ?
>     libqtc.sipRegisterClasses()
> RuntimeError: SIP - module "qt" implements QObject but it has already been
> implemented
>
> ########################## (with PYTHONVERBOSE)
> # /opt/Embedix/usr/lib/python2.0/site.pyc matches /opt/Embedix/usr/lib/python2.0
> /site.py
> import site # precompiled from /opt/Embedix/usr/lib/python2.0/site.pyc
> # /opt/Embedix/usr/lib/python2.0/os.pyc matches /opt/Embedix/usr/lib/python2.0/o
> s.py
> import os # precompiled from /opt/Embedix/usr/lib/python2.0/os.pyc
> import posix # builtin
> # /opt/Embedix/usr/lib/python2.0/posixpath.pyc matches /opt/Embedix/usr/lib/pyth
> on2.0/posixpath.py
> import posixpath # precompiled from /opt/Embedix/usr/lib/python2.0/posixpath.pyc
> # /opt/Embedix/usr/lib/python2.0/stat.pyc matches /opt/Embedix/usr/lib/python2.0
> /stat.py
> import stat # precompiled from /opt/Embedix/usr/lib/python2.0/stat.pyc
> # /opt/Embedix/usr/lib/python2.0/UserDict.pyc matches /opt/Embedix/usr/lib/pytho
> n2.0/UserDict.py
> import UserDict # precompiled from /opt/Embedix/usr/lib/python2.0/UserDict.pyc
> test #1 - simple assignment and print
> a= 7
> test #9.1 - importing qt
> # /opt/Embedix/usr/lib/python2.0/site-packages/qt.pyc matches /opt/Embedix/usr/l
> ib/python2.0/site-packages/qt.py
> import qt # precompiled from /opt/Embedix/usr/lib/python2.0/site-packages/qt.pyc
> import libqtc # dynamically loaded from /opt/Embedix/usr/lib/python2.0/site-pack
> ages/libqtcmodule.so
> # clear __builtin__._
> # clear sys.path
> # clear sys.argv
> # clear sys.ps1
> # clear sys.ps2
> # clear sys.exitfunc
> # clear sys.exc_type
> # clear sys.exc_value
> # clear sys.exc_traceback
> # clear sys.last_type
> # clear sys.last_value
> # clear sys.last_traceback
> # restore sys.stdin
> # restore sys.stdout
> # restore sys.stderr
> # cleanup __main__
> # cleanup[1] exceptions
> # cleanup[1] posix
> # cleanup[1] qt
> # cleanup[1] libqtc
> # cleanup[1] site
> # cleanup[1] signal
> # cleanup[2] os.path
> # cleanup[2] os
> # cleanup[2] UserDict
> # cleanup[2] posixpath
> # cleanup[2] stat
> # cleanup sys
> # cleanup __builtin__
> # cleanup ints: 33 unfreed ints in 2 out of 7 blocks
> # cleanup floats
> # /opt/Embedix/usr/lib/python2.0/site.pyc matches /opt/Embedix/usr/lib/python2.0
> /site.py
> import site # precompiled from /opt/Embedix/usr/lib/python2.0/site.pyc
> # /opt/Embedix/usr/lib/python2.0/os.pyc matches /opt/Embedix/usr/lib/python2.0/o
> s.py
> import os # precompiled from /opt/Embedix/usr/lib/python2.0/os.pyc
> import posix # builtin
> # /opt/Embedix/usr/lib/python2.0/posixpath.pyc matches /opt/Embedix/usr/lib/pyth
> on2.0/posixpath.py
> import posixpath # precompiled from /opt/Embedix/usr/lib/python2.0/posixpath.pyc
> # /opt/Embedix/usr/lib/python2.0/stat.pyc matches /opt/Embedix/usr/lib/python2.0
> /stat.py
> import stat # precompiled from /opt/Embedix/usr/lib/python2.0/stat.pyc
> # /opt/Embedix/usr/lib/python2.0/UserDict.pyc matches /opt/Embedix/usr/lib/pytho
> n2.0/UserDict.py
> import UserDict # precompiled from /opt/Embedix/usr/lib/python2.0/UserDict.pyc
> test #9.2 - try re-importing qt
> # /opt/Embedix/usr/lib/python2.0/site-packages/qt.pyc matches /opt/Embedix/usr/l
> ib/python2.0/site-packages/qt.py
> import qt # precompiled from /opt/Embedix/usr/lib/python2.0/site-packages/qt.pyc
> import libqtc # dynamically loaded from /opt/Embedix/usr/lib/python2.0/site-pack
> ages/libqtcmodule.so
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
>   File "/opt/Embedix/usr/lib/python2.0/site-packages/qt.py", line 1173, in ?
>     libqtc.sipRegisterClasses()
> RuntimeError: SIP - module "qt" implements QObject but it has already been imple
> mented
> # clear __builtin__._
> # clear sys.path
> # clear sys.argv
> # clear sys.ps1
> # clear sys.ps2
> # clear sys.exitfunc
> # clear sys.exc_type
> # clear sys.exc_value
> # clear sys.exc_traceback
> # clear sys.last_type
> # clear sys.last_value# restore sys.stdin
> # restore sys.stdout
> # restore sys.stderr
> # cleanup __main__
> # cleanup[1] exceptions
> # cleanup[1] posix
> # cleanup[1] qt
> # cleanup[1] libqtc
> # cleanup[1] site
> # cleanup[1] signal
> # cleanup[2] os.path
> # cleanup[2] os
> # cleanup[2] UserDict
> # cleanup[2] posixpath
> # cleanup[2] stat
> # cleanup sys
> # cleanup __builtin__
> # cleanup ints: 33 unfreed ints in 2 out of 5 blocks
> # cleanup floats
> # clear sys.last_traceback
> ____________________________________________________________
> Tim Bird                                  Lineo, Inc.
> Chief Technology Officer                  390 South 400 West
> tbird at lineo.com                           Lindon, UT 84042
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qttest.tgz
Type: application/octet-stream
Size: 887 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20010307/e8c781db/qttest.obj


More information about the PyQt mailing list