Hi there, I'm having some problems with a fairly simple multi-threaded application under PyQt 4.5.4 and Windows XP. I have a number of worker threads that feed one consumer in the main GUI thread. Initially I had the worker threads directly call the "add" method of the consumer object; this piece of code was protected by a mutex. So in short:
class Worker(QThread): def run(self): ... cache.add(link) class Cache(): def add(self, link): mutex.lock() # Add link to queue mutex.unlock() cache = Cache() This works pretty well but still I'm not completely satisfied. It's bad to execute code that doesn't belong to your thread, right? So I tried to replace that with a signal/slot mechanism: class Worker(QThread): addLink = pyqtSignal(Link) def init(self): self.addLink.connect(cache.add) def run(self): ... link = Link(blah blah) self.addLink.emit(link) class Cache(QObject): def add(self, link): # Add link to queue # No more mutex since access is now serial, right ? ... However the application freezes after a while. No more GUI activity, window not even repainting anymore and Windows tells me "this application is not responding etc" when trying to close. This doesn't happen if I use Qt.DirectConnection or Qt.BlockingQueuedConnection it seems, although I have no idea why. I also notice that with Qt.AutoConnection, the application crashes with no error message unless I use 'PyQt_PyObject' types, with the quotes, in all signal definitions (instead of Link for instance); I don't have this problem either when using Qt.DirectConnection or Qt.BlockingQueuedConnection. So does anyone understand what's going on here under the hood? Is the signal/slot approach the correct way to garantee serial access to a shared resource between threads (the link queue in this example)? Why is this whole thing crashing and freezing like that? Thanks for sharing your insight! Chris -- View this message in context: http://www.nabble.com/Freezes-and-crashes-with-signal-autoconnection-tp25716493p25716493.html Sent from the PyQt mailing list archive at Nabble.com. _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt