0

I was wondering if anyone had any ideas on why the following PyQt signal/slot setup would work, while adding in multiprocessing will cause the GUI not to update. The signals are sent through in both cases, but the signal/slot can update the GUI, while the multiprocessing layout does not.

Here is the general setup that I have: For PyQt Signals and Slots I have this, which works:

# signals and slots 
class Worker(QObject):
    ...
    # send signals in for loop to tab
    ...

class Tab(QTabWidget):
    ...
    # start thread
    ...
    # get signals and update GUI

class MainWindow:
    ...
    # make GUI stuff
    ...
    # start worker process

While this multiprocessing code does not:

# signals and slots *with multiprocessing*
class Worker(QObject):
    ...
    # send messages down a pipe in for loop to tab
    ...
class Worker_thread(QThread):
    ...
    # start process
    ...
    # get messages from Worker and send signals to update GUI function in Tab

class Tab(QTabWidget):
    ...
    # start Worker_Thread
    ...
    # get signals and update GUI

class MainWindow:
    ...
    # make GUI stuff
    ...
    # start Worker_thread process

Here is the function that gets messages from the Worker and sends signals to update the GUI in the multiprocessing case:

@QtCore.pyqtSlot()
def start_computation(self):
    self.process.start()
    while(True):
        try:
            message = self.consumer.recv()
            self.update_signal.emit(message)
        except EOFError:
            pass
        if message == 'done with processing':
            self.done_signal.emit()
            break
        #self.parent.update_GUI(message)
    self.process.join()
    return

Do I need to close the Pipe somewhere in here? It has to constantly be reading the process for it's progress and updating the GUI throughout, so I don't know where that would be appropriate.

Also, there are some full code examples of this here:

multiprocessing GUI schemas to combat the "Not Responding" blocking

and here:

https://stackoverflow.com/questions/15754826/gui-not-responding-general-multithreading-and-multprocessing-architecture?lq=1

Any help is much appreciated.

Community
  • 1
  • 1
chase
  • 3,592
  • 8
  • 37
  • 58
  • 1
    Read more about QEventLoop. You need to process event inside the loop or yout UI will freeze. Or you can use [QtConcurrentRun](http://qt-project.org/doc/qt-4.8/qtconcurrentrun.html) – Md. Minhazul Haque Apr 04 '13 at 18:06
  • QtCore.QtConcurrent does not exist for python due to the GIL. – chase Apr 05 '13 at 16:35

0 Answers0