[PyQt] Disturbing evidence of garbage collection error

Andrew Suffield asuffield at suffields.me.uk
Fri Apr 27 12:53:20 BST 2012


        query = QtSql.QSqlQuery()
        if not query.prepare('select %s from %s where %s' % (','.join(field_names), table, self.key_expr(table))):

I get 'RuntimeError: underlying C/C++ object has been deleted' on the
second line, with low probability. Sometimes it just segfaults instead
while inside the C++ function QSqlQuery::prepare. Either way, it
happens about one time in 100,000, and when it segfaults, a different
thread is in the garbage collector.

So, we've got one thread deciding that the local python variables of
another are garbage and freeing them, while the victim thread is still
in a function call. That implies the local variables are somehow not
getting registered properly as being referenced.

I'll keep digging, but some ideas or pointers to relevant code would
be handy - it's not immediately clear how sip interacts with GC.


More information about the PyQt mailing list