首页 > 解决方案 > 如何停止接收 QThread?

问题描述

我有一个 QThread 对象,我想从主程序中停止它,但它卡在了 recv 方法中。有没有办法在调用 close_worker 函数时停止 recv 方法?

# Main function of the thread

    def handle:
        while self.run:
            data = sock.recv(data_size)
            self.intReady.emit(msg) 


# Stop the thread

def close_worker(self):
    self._mutex.lock()
    self.run = False
    self._mutex.unlock()

标签: pythonpyqt5qthread

解决方案


推荐阅读