Details
Description
When the waitForXXX blocking function is executed in a secondary thread, the main thread is also blocked. In the following example the time is printed every T seconds but when the waitForRead method is executed in a secondary thread it blocks the main eventloop so the QTimer is no longer fired.
from PySide6 import QtCore, QtNetwork class Runnable(QtCore.QRunnable): def run(self): socket = QtNetwork.QTcpSocket() socket.connectToHost("example.com", 80) if not socket.waitForConnected(5 * 1000): print("Not Connected") return print("Connected") if not socket.waitForReadyRead(10 * 1000): print("Timeout") return print("Answer received") def handle_timeout(): dt = QtCore.QDateTime.currentDateTime() print(dt.toString()) def main(): app = QtCore.QCoreApplication() timer = QtCore.QTimer(interval=100, timeout=handle_timeout) timer.start() runnable = Runnable() QtCore.QThreadPool.globalInstance().start(runnable) QtCore.QTimer.singleShot(15 * 1000, app.quit) app.exec() if __name__ == "__main__": main()
The bug is observed with PySide2 and PySide6 but in PyQt it works correctly.