[PyKDE] Re: [C++-sig] Can boost.python and PyQt be used together?

Phil Thompson phil at river-bank.demon.co.uk
Tue Dec 10 10:55:01 GMT 2002


On Tuesday 10 December 2002 1:21 am, Paul F. Kunz wrote:
>    Its me again.   This time, I've got my Python extension modules
> working completely with Boost.Python wrapped alone.   That is...
>
> [pfkeb at Kunz-pbdsl1 testsuite]$ python
> Python 2.2.2 (#1, Oct 15 2002, 07:42:56)
> [GCC 2.95.3 20010315 (release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> from hippo import *
> >>> app = HDApp(1)
> >>> cw = CanvasWindow()
> >>> cw.show()
> >>> app.exec_loop()
>
> works fine.   In the above, `HDApp' is not derived from
> QApplication, but delegates to a class which does.   CanvasWindow
> wraps a C++ class which derives from QMainWindow.
>
> Now I modify the dclock.py example that comes with PyQt to...
>
> a = QApplication(sys.argv)
> clock = DigitalClock()
> clock.resize(170,80)
> a.setMainWidget(clock)
> clock.show()
>
> cw = CanvasWindow() # added
> cw.show()           # added
>
> a.exec_loop()
>
> and get ...
>
> Starting program: /usr/local/bin/python
> /home/pfkeb/hippodraw-BUILD/testsuite/dclock.py [New Thread 1024 (LWP
> 5948)]
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 1024 (LWP 5948)]
> PyErr_SetObject (exception=0x8108a8c, value=0x81ab208) at
> Python/errors.c:39 (gdb) bt
> #0  PyErr_SetObject (exception=0x8108a8c, value=0x81ab208)
>     at Python/errors.c:39
> #1  0x08087ac7 in PyErr_Format (exception=0x8108a8c,
>     format=0x80df620 "%.50s instance has no attribute '%.400s'")
>     at Python/errors.c:408
> #2  0x080b0467 in instance_getattr1 (inst=0x82c5654, name=0x8154558)
>     at Objects/classobject.c:678
> #3  0x080b3e35 in instance_getattr (inst=0x82c5654, name=0x8154558)
>     at Objects/classobject.c:715
> #4  0x40cd2a43 in instanceGetAttr ()
>    from /usr/local/lib/python2.2/site-packages/libsip.so
> #5  0x08056794 in PyObject_GetAttr (v=0x82c5654, name=0x8154558)
>     at Objects/object.c:1108
> #6  0x0807705e in eval_frame (f=0x811a974) at Python/ceval.c:1784
> #7  0x0807866e in PyEval_EvalCodeEx (co=0x8161de0, globals=0x81139b4,
>     locals=0x81139b4, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0,
>     defcount=0, closure=0x0) at Python/ceval.c:2595
> #8  0x0807a700 in PyEval_EvalCode (co=0x8161de0, globals=0x81139b4,
>     locals=0x81139b4) at Python/ceval.c:481
> #9  0x080950b1 in run_node (n=0x81263b8,
>     filename=0xbffffca2 "/home/pfkeb/hippodraw-BUILD/testsuite/dclock.py",
>     globals=0x81139b4, locals=0x81139b4, flags=0xbffffac4)
>     at Python/pythonrun.c:1079
> #10 0x08095062 in run_err_node (n=0x81263b8,
>     filename=0xbffffca2 "/home/pfkeb/hippodraw-BUILD/testsuite/dclock.py",
>     globals=0x81139b4, locals=0x81139b4, flags=0xbffffac4)
>     at Python/pythonrun.c:1066
> #11 0x08094ccb in PyRun_FileExFlags (fp=0x8104038,
>     filename=0xbffffca2 "/home/pfkeb/hippodraw-BUILD/testsuite/dclock.py",
>     start=257, globals=0x81139b4, locals=0x81139b4, closeit=1,
>     flags=0xbffffac4) at Python/pythonrun.c:1057
> #12 0x080938b1 in PyRun_SimpleFileExFlags (fp=0x8104038,
>     filename=0xbffffca2 "/home/pfkeb/hippodraw-BUILD/testsuite/dclock.py",
>     closeit=1, flags=0xbffffac4) at Python/pythonrun.c:685
> #13 0x0809481f in PyRun_AnyFileExFlags (fp=0x8104038,
>     filename=0xbffffca2 "/home/pfkeb/hippodraw-BUILD/testsuite/dclock.py",
>     closeit=1, flags=0xbffffac4) at Python/pythonrun.c:495
> #14 0x08053632 in Py_Main (argc=2, argv=0xbffffb54) at Modules/main.c:364
> #15 0x08052ee6 in main (argc=2, argv=0xbffffb54) at Modules/python.c:10
> #16 0x40088627 in __libc_start_main (main=0x8052ed0 <main>, argc=2,
>     ubp_av=0xbffffb54, init=0x80522d4 <_init>, fini=0x80cf610 <_fini>,
>     rtld_fini=0x4000dcd4 <_dl_fini>, stack_end=0xbffffb4c)
>     at ../sysdeps/generic/libc-start.c:129
> (gdb)
>
>    On the line of the error
>
> 	oldtype = tstate->curexc_type;
>
> (gdb) p tstate
> $1 = (PyThreadState *) 0x0
> (gdb)
>
>    It really appears to me that Boost.Python extensions and SIP Python
> extensions are incompatible with each other.   Or there is still
> something that I'm doing wrong.

The only area of possible conflict I can think of is threads, the following is 
from the PyQt docs...

"PyQt implements the full set of Qt's thread classes.  Python, of course, also 
has its own thread extension modules.  It is possible to use either of the 
APIs so long as you follow some simple rules.

If you use the Qt API then the very first import of one of the PyQt modules 
must be done from the main thread.

If you use the Python API then all calls to PyQt (including any imports must 
be done from one thread only.  Therefore, if you want to make calls to PyQt 
from several threads then you must use the Qt API.

If you want to use both APIs in the same application then all calls to PyQt 
must be done from threads created using the Qt API."

Another possible conflict, perhaps more likely, is the two modules fighting 
over the Qt API.

Phil




More information about the PyQt mailing list