[solved] Worker QThread stops working about 30 secs after main window loses focus
-
Hi all,
I am trying to get a worker thread doing some routing (takes about 5 min) in a slippy map implemented with PyQt4 (4.10.3) and Qt (4.8.5) on OSX (10.9.2).
Everything is working as long as the main window keeps focus. About 30 secs after the main window loses focus, the thread will stop working. When the main window gets focus again, the thread will continue.
Unfortunately, I did not find any hint why this is happening. Thanks for any suggestions.@class MapWindow(PyQt4.QtGui.QMainWindow):
def init(self):
super(MapWindow, self).init(None)
widget = MapWidget(self)
self.setCentralWidget(widget)
widget.setFocus()class MapWidget(PyQt4.QtGui.QWidget):
def init(self, parent=None):
super(MapWidget, self).init(parent)
self.osm = osm(...)
self.run_in_thread(self.osm, self.osm.parse_and_route, self.osm_changed)
def run_in_thread(self, obj, function, callback):
self.thread = PyQt4.QtCore.QThread()
obj.moveToThread(self.thread)
obj.finished.connect(callback)
obj.finished.connect(self.thread.quit)
self.thread.started.connect(function)
self.thread.start()class osm(PyQt4.QtCore.QObject):
finished = PyQt4.QtCore.pyqtSignal()
def init(self, ...):
PyQt4.QtCore.QObject.init(self)
...
def parse_and_route(self):
self.parse()
self.route()
self.finished.emit()def show_window():
app = PyQt4.QtGui.QApplication(sys.argv)
w = MapWindow()
w.showMaximized()
w.raise_()
app.exec_()if name == 'main':
show_window()
@ -
Hi and welcome to devnet,
Since you're on Mavericks, you might be "benefiting" from the new App Nap feature.
Have a look at this "thread":http://qt-project.org/forums/viewthread/37750
Hope it helps
-
Thank you very much! Disabling App Nap for Python with "defaults write org.python.python NSAppSleepDisabled -bool YES" did indeed solve the problem. Thanks again for the quick reply
-
You're welcome !
Since you have your application working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)