[PyKDE] Using thread and event filter crashes Python

Yann COINTEPAS yann at sapetnioc.org
Wed Jul 6 09:40:41 BST 2005


Setting an event filter to the QApplication singleton and using threads lead 
to a Python crash due to a double deletion of a widget (at Python level). 
This happens with PyQt 3.14.1 and sip 4.2.1. I don't know if it is the same 
for other versions.

For example, the following code:

import sys, threading
from qt import *

class EventFilter( QObject ):
  def eventFilter( self, o, e ):
    return False

class TestWidget( QWidget ):
  def __init__( self ):
    print '!init TestWidget!', threading.currentThread()
    QWidget.__init__( self )

  def __del__( self ):
    print '!del TestWidget!', threading.currentThread()

def createWidget():
  qApp.lock()
  try:
    w = TestWidget()
    w.show()
    del w
  finally:
    qApp.unlock()


app = QApplication( sys.argv )

theEventFilter = EventFilter()
qApp.installEventFilter( theEventFilter )

main = QLabel( 'main', None )
main.show()
app.setMainWidget( main )

t = threading.Thread( target=createWidget )
t.start()

app.exec_loop()


Produces the following output:

!init TestWidget! <Thread(Thread-1, started)>
!del TestWidget! <Thread(Thread-1, started)>
!del TestWidget! <Thread(Thread-1, started)>
Segmentation fault

I even try to create widgets only from the main thread (instead of using 
qApp.lock/qApp.unlock) by using a QTimer and a queue of functions and 
arguments. But the result is the same.
-- 
Yann Cointepas                         Tel: +33 1 69 86 78 52
CEA - SHFJ                             Fax: +33 1 69 86 77 86
4, place du General Leclerc
91401 Orsay Cedex France




More information about the PyQt mailing list