[PyKDE] Re: PyEval_RestoreThread Error

Phil Thompson phil at riverbankcomputing.co.uk
Fri Aug 22 18:02:00 BST 2003


On Friday 22 August 2003 2:50 am, Michael Andrews wrote:
> On Thu, 2003-08-21 at 07:05, Michael Andrews wrote:
> > I don't know if this is a Python, Qt, or PyQt issue.  I thought I'd
> > start with PyQt and we'll see where it leads.  I am trying to build a
> > new Python/Qt environment consisting of:
> >   Python 2.3, Qt-3.2.0, sip-3.8, and PyQt-3.8
> > When I run the bug_test.py script below and then immediately press the
> > Quit button, python dumps core with the following error:
> >
> >   Fatal Python error: PyEval_RestoreThread: NULL tstate
> >
> > The problem appears to be the fact that my UIMainC class (the
> > controller) has a member which is the AppClass and the AppClass has a
> > member which is the controller.  If I remove the UIMainC.app everything
> > works.
>
> Sorry for the delayed reply.  I couldn't get to my email sooner and I
> wanted to do some more experimentation.  I'll try to respond to both
> followups at the same time.
>
> Phil wrote:
> > Because of the circular reference count you've created I suspect that
> > PyQt is having trouble arranging for dtors to be called in a sensible
> > order.
>
> This I think is the core of the problem; but why did it work before?  It
> is the same problem dtor order problem.  There is a Python version issue
> here too (see below).

If it was dependent on the version of Python, then maybe the code that 
implements dictionaries has changed. But, from your matrix below, it's the 
version of Qt that seems to make the difference.

> > IMHO, passing self as a function/method argument from an __init__()
> > method is dubious because there is the danger that the instance will
> > be used when it hasn't been fully initialised.
>
> While I suppose this is probably better practice, it is not a factor in
> this problem.  I moved the last two lines from the AppClass.__init__()
> function into AppClass.execute() with the same crashes.
>
> Pete wrote:
> > I had similar problems with very simple test scripts, which resulted
> > from races in the dtors of python and pyqt classes. You can prove this
> > theory with this patch:
>
>   <patch snipped>
>
> I tried the patch, it crashes in exactly the same way.  In fact, any
> method of exiting, seems to cause the same PyEval_RestoreThread error.
> My simple test script came from a more complex application which was
> crashing the same way.  I just didn't want to post that to the list ;-).
>
> > BTW: on Python 2.2.2, Qt 3.1.1, sip/PyQt 3.8 ii works flawlessly both
> > ways, (after fixing the obvious intention error)..
>
> I have done some 'version checking'.  Here's my result matrix under
> Redhat-9:
>
>   Python  Qt     sip       PyQt       Status
>   2.2.2   3.1.1  20030416  20030418   WORKS
>   2.2.3   3.2.0  3.8       3.8        FAILS
>   2.3.0   3.2.0  3.8       3.8        FAILS
>   2.2.2   3.2.0  3.8       3.8        FAILS
>
> I'm continuing my build regression testing.  I think my next test will
> be Python 2.3.0, Qt 3.1.1, sip3.8, PyQt3.8.  Stay turned.

That's the test I'd do.

Phil




More information about the PyQt mailing list