Re: [PyQt] isRunning() returns true after QThread completion
Dear Lars, On Sunday 26 February 2012, 15:55:25 Lars Beiderbecke wrote: > Hello, > > In my application some QThreads still return isRunning() == true when > they should be completed. > > More specifically, I'm using QThreads to load images asynchronously > in the background. By emitting a signal, the thread notifies the > main window that the pixmap has been loaded and the corresponding > widget can be updated (code has been simplified): > > class ImgRequest(QtCore.QThread): > def run(self): > # ... load image ... > self.emit(QtCore.SIGNAL("sigDone"), self) > > class MainWindow(QtGui.QMainWindow): > self.requests = set() > > def request(self, filename): > t = ImgRequest(self, filename) > self.connect(t, QtCore.SIGNAL("sigDone"), self.ack) > self.requests.add(t) > t.start() > > def ack(self, t): > # ... update image ... > if t.isRunning(): > print "WARNING: thread still running" > t.wait() > self.requests.remove(t) > > When I run above code, however, I'll often get WARNING messages, > i.e., QThread.isRunning() is returning true even though its > corresponding run() method has been completed. > > Is this merely a race condition between the signal and the actual > completion of run(), or am I missing something fundamental about > QThreads? Do I really need isRunning() and wait()? Since you don't provide a runnable snippet, all I can do is guessing: check out the Qt.ConnectionType parameter of connect, especially QueuedConnection and BlockingQueuedConnection, and see, if they do, what you're after. While at it, please check out http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html to further improve your code. > And finally, is > there a better way to deal with the QThread objects than storing them > in a set so that the GC won't kill them while running? Any scheme, that keeps the thread object reference alive, is fine. BTW, the definition of your requests object is wrong. Either initialize it as an instance variable in __init__ or any subsequent method, or as a class variable omitting self. For the sake of clean code, I would prefer the latter, even in the light of a single instance QMainWindow. Finally, you should limit the number of threads to a sane maximum. Pete ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] pylupdate4 issue
Am Sonntag, 26. Februar 2012, 15:56:54 schrieb Vincent Vande Vyvre: > Le 26/02/12 15:16, ad...@mbnoimi.net a écrit : > On 19/02/2012 09:55 م, Vincent Vande Vyvre wrote: > Le 19/02/12 19:55, ad...@mbnoimi.net a écrit : > On 19/02/2012 08:22 م, ad...@mbnoimi.net wrote: > Hi all, > > I tried to create *.ts file for my project by using pylupdate4 so I tried > the following commad but it didn't work! > > pylupdate4 *.py -ts %CD%\ui\l10n\ar.ts > pylupdate4 error: Cannot open file '*.py': No error > > Could you please guide me to the correct path? > > PS > I successfully created *.ts file for single *.py file. > > I forgot to mention that I want to create single *.ts file for many *.py > files > > You must provide a .pro file to pyludate4 > > exemple of .pro file > > SOURCES= main.py\ > ui_mainWindow.py\ > otherFile.py\ > etc > > TRANSLATIONS= appName_ar.ts > > CODECFORTR = UTF-8 > > CODECFORSRC = UTF-8 > > I don't want to use .pro because I've many files in many subdirecories which > is very exhausting to write manually. > > Any ideas guys? > > -- > Best Regards > Muhammad Bashir Al-Noimi > My Blog: http://mbnoimi.net > So, You can easily write a python script which will create the .pro file for > you. No? You could copy the relevant code from the eric4/eric5 sources (module ProjectLanguagesBrowser). Regards, Detlev -- Detlev Offenbach det...@die-offenbachs.de ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QWidget 'destroyed' signal: possible regression?
Hi Phil, I recently found out that a feature succesfully tested with older versions of PyQt was broken (http://code.google.com/p/spyderlib/issues/detail?id=951) and at the same time the Matplotlib developers contacted me for a similar issue (https://github.com/matplotlib/matplotlib/issues/711). To explain our problem, I wrote this test script: #- from PyQt4.QtGui import QApplication, QWidget from PyQt4.QtCore import Qt def print_from_function(): print "Callback = Function" class TestWidget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.destroyed.connect(print_from_function) self.destroyed.connect(self.print_from_method) self.destroyed.connect(self.print_from_static_method) self.destroyed.connect(lambda: self.print_from_lambda_function()) self.setAttribute(Qt.WA_DeleteOnClose) def print_from_method(self): print "Callback = method" @staticmethod def print_from_static_method(self): print "Callback = static method" def print_from_lambda_function(self): print "Callback = lambda function" app = QApplication([]) widget = TestWidget() widget.show() app.exec_() #- The issue with the test script above is that all callbacks connected to the 'destroyed' signal are triggered except for the callback which is a method (bound to the object to be destroyed). So the question is: is this a regression from PyQt v4.8.5? (or earlier) Thanks, -Pierre ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] pylupdate4 issue
Le 26/02/12 15:16, ad...@mbnoimi.net a écrit : On 19/02/2012 09:55 م, Vincent Vande Vyvre wrote: Le 19/02/12 19:55, ad...@mbnoimi.net a écrit : On 19/02/2012 08:22 م, ad...@mbnoimi.net wrote: Hi all, I tried to create *.ts file for my project by using pylupdate4 so I tried the following commad but it didn't work! pylupdate4 *.py -ts %CD%\ui\l10n\ar.ts pylupdate4 error: Cannot open file '*.py': No error Could you please guide me to the correct path? PS I successfully created *.ts file for single *.py file. I forgot to mention that I want to create single *.ts file for many *.py files You must provide a .pro file to pyludate4 exemple of .pro file SOURCES = main.py\ ui_mainWindow.py\ otherFile.py\ etc TRANSLATIONS = appName_ar.ts CODECFORTR = UTF-8 CODECFORSRC = UTF-8 I don't want to use .pro because I've many files in many subdirecories which is very exhausting to write manually. Any ideas guys? -- Best Regards Muhammad Bashir Al-Noimi My Blog: http://mbnoimi.net So, You can easily write a python script which will create the .pro file for you. No? -- Vincent V.V. Oqapy . Qarte+7 . PaQager ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] isRunning() returns true after QThread completion
Hello, In my application some QThreads still return isRunning() == true when they should be completed. More specifically, I'm using QThreads to load images asynchronously in the background. By emitting a signal, the thread notifies the main window that the pixmap has been loaded and the corresponding widget can be updated (code has been simplified): class ImgRequest(QtCore.QThread): def run(self): # ... load image ... self.emit(QtCore.SIGNAL("sigDone"), self) class MainWindow(QtGui.QMainWindow): self.requests = set() def request(self, filename): t = ImgRequest(self, filename) self.connect(t, QtCore.SIGNAL("sigDone"), self.ack) self.requests.add(t) t.start() def ack(self, t): # ... update image ... if t.isRunning(): print "WARNING: thread still running" t.wait() self.requests.remove(t) When I run above code, however, I'll often get WARNING messages, i.e., QThread.isRunning() is returning true even though its corresponding run() method has been completed. Is this merely a race condition between the signal and the actual completion of run(), or am I missing something fundamental about QThreads? Do I really need isRunning() and wait()? And finally, is there a better way to deal with the QThread objects than storing them in a set so that the GC won't kill them while running? Regards Lars ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] pylupdate4 issue
On 19/02/2012 09:55 م, Vincent Vande Vyvre wrote: Le 19/02/12 19:55, ad...@mbnoimi.net a écrit : On 19/02/2012 08:22 م, ad...@mbnoimi.net wrote: Hi all, I tried to create *.ts file for my project by using pylupdate4 so I tried the following commad but it didn't work! pylupdate4 *.py -ts %CD%\ui\l10n\ar.ts pylupdate4 error: Cannot open file '*.py': No error Could you please guide me to the correct path? PS I successfully created *.ts file for single *.py file. I forgot to mention that I want to create single *.ts file for many *.py files You must provide a .pro file to pyludate4 exemple of .pro file SOURCES = main.py\ ui_mainWindow.py\ otherFile.py\ etc TRANSLATIONS = appName_ar.ts CODECFORTR = UTF-8 CODECFORSRC = UTF-8 I don't want to use .pro because I've many files in many subdirecories which is very exhausting to write manually. Any ideas guys? -- Best Regards Muhammad Bashir Al-Noimi My Blog: http://mbnoimi.net ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt