我正在编写初始屏幕(这是辅助窗口),并且出现了非常奇怪的行为, 有时启动屏幕死机并且根本不响应(事件是关闭窗口)
我正在使用 PyQt 5.9.2 。
main.py
if __name__ == "__main__":
APP = QApplication([])
splash_loader = SplashScreen()
splash_loader.start()
sys.exit(APP.exec())
此主应用创建一个启动画面实例并调用.start()
。
问题在于它仅在某些情况下发生(例如,约10次发生1次)。
splashScreen.py
class SplashScreen(QWidget):
finished = pyqtSignal()
def __init__(self):
super().__init__()
self._canceled = False
self._connection_check_thread = threading.Thread(target=self.wait_for_connection, daemon=True)
self._event_loop = QEventLoop()
def start(self):
self.show()
self._connection_check_thread.start()
self._event_loop.exec_()
self.hide()
def wait_for_connection(self):
""" used to have connection check to some ip
but in my case the problem happen even if the connection check
returned True right away
"""
for _in range (5):
pass
self.abort_connecting()
def abort_connecting(self):
self._canceled = True
self._event_loop.quit()
def closeEvent(self, QCloseEvent):
self.abort_connecting()