The attached script creates a threading.local within a QThread, and stores a value in it. It then reads this value back immediately, and later from an event handler.
Unexpectedly, by the time we get to the event handler, the contents of the threading.local has been destroyed. I suspect there are infelicitious interactions between QThread, thread._local, and the garbage collector. I haven't looked closely; it's easier to work around the problem. It's possible this is a python bug in the handling of alien threads. Tripped over this one because it breaks sqlalchemy's scoped_session
import sys from PyQt4.QtCore import * from PyQt4 import QtGui import threading class Blob(object): def __del__(self): print "Deleted!" class Worker(QObject): @pyqtSlot() def start(self): self.local = threading.local() self.local.value = Blob() self.timer = QTimer() self.timer.setInterval(1000) self.timer.timeout.connect(self.timeout) self.timer.setSingleShot(True) self.timer.start() print getattr(self.local, 'value', None) def timeout(self): print getattr(self.local, 'value', None) class Caller(QObject): start = pyqtSignal() app = QtGui.QApplication(sys.argv) thread = QThread() worker = Worker() worker.moveToThread(thread) thread.start() caller = Caller() caller.start.connect(worker.start) caller.start.emit() sys.exit(app.exec_())
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt