多处理无法更新GUI

时间:2013-04-04 15:29:32

标签: python multithreading qt user-interface multiprocessing

我想知道是否有人对以下PyQt信号/插槽设置的原因有任何想法,而添加多处理会导致GUI无法更新。在这两种情况下都会发送信号,但信号/插槽可以更新GUI,而多处理布局则不会。

以下是我的常规设置: 对于PyQt信号和插槽我有这个,它有效:

# 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

虽然这个多处理代码没有:

# 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

这是从工作者获取消息并在多处理情况下发送信号以更新GUI的函数:

@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

我是否需要关闭此处某处的Pipe?它必须不断地阅读整个过程的进程和更新GUI,所以我不知道哪个是合适的。

此外,这里有一些完整的代码示例:

multiprocessing GUI schemas to combat the "Not Responding" blocking

在这里:

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

非常感谢任何帮助。

0 个答案:

没有答案