[PyKDE] Thread Support in 3.0.4 broke use of PyRun_SimpleFile

Robin Summerhill robinsummerhill at cyantechnology.com
Tue May 21 17:29:12 BST 2002


Hi,

I'm embedding Python/PyQT in a C++/Qt app (Qt 3.0.3 + MSVC6 and Linux). I
want to allow the user to extend the app by writing 'macro' files in
Python/PyQT that are run by the app using PyRun_SimpleFile. The scheme I was
using worked fine with sip/PyQt3.1 but is broken with sip/PyQT3.2. (Of
course, it might be that my way of doing things is 'broken' :-) )

To check things out, I created a minimal C++/Qt app that just has a single
button on a dialog. Pressing the button calls the slot function below:

void MacroDialog::slotRunMacro()
{
	FILE* fp;
	fp = fopen("macro.py", "r");
	PyRun_SimpleFile(fp, "macro.py");
	fclose(fp);
}

macro.py looks like this:

import qt
a = qt.QLabel("Hello", None)
a.show()

Everything is fine the first time that you run the macro. However, the
second time you run it within the same session you get
'Py_FatalError("PyThreadState_Get: no current thread")' at line 236 of
pystate.c. The callstack shows that PyRun_SimpleFile is trying to call
PyImport_AddModule to create the '__main__' module. This calls
PyThreadGetState_Get() which bombs out because _PyThreadState_Current has
been set to NULL.

I'm pretty sure that _PyThreadState_Current has been set to NULL by a call
to SIP_UNBLOCK_THREADS in sipIsPyMethod(). I'm not that hot on Python thread
states and the new thread support in PyQT3.0.4 though .

Does anyone have a clue what is going on and whether it's me at fault or sip
or pyqt?

Thanks for any help,
Robin




More information about the PyQt mailing list