Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Worker QThread stops working about 30 secs after main window loses focus
Forum Updated to NodeBB v4.3 + New Features

[solved] Worker QThread stops working about 30 secs after main window loses focus

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sgrewe
    wrote on last edited by
    #1

    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()
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sgrewe
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved