zoukankan      html  css  js  c++  java
  • pyqt点击右上角关闭界面但子线程仍在运行

    现象:

    通过右上角的叉关闭图形界面后,程序运行的子线程却不会被自动关闭,依然留存在系统中
    原因:

    子线程没有正确关闭

    解决方法:

    1.将子线程设置成守护线程

    self.your_thread = threading.Thread(target=self.tcp_client_concurrency)
    # 设置线程为守护线程,防止退出主线程时,子线程仍在运行
    self.your_thread.setDaemon(True)
    # 新线程启动
    self.your_thread.start()
    

    2.重构 def closeEvent(self, event): 函数

        def closeEvent(self, event):
            """
            对MainWindow的函数closeEvent进行重构
            退出软件时结束所有进程
            :param event:
            :return:
            """
            reply = QtWidgets.QMessageBox.question(self,
                                                   '本程序',
                                                   "是否要退出程序?",
                                                   QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
                                                   QtWidgets.QMessageBox.No)
            if reply == QtWidgets.QMessageBox.Yes:
                event.accept()
                os._exit(0)
            else:
                event.ignore()
    
    
    ##### 愿你一寸一寸地攻城略地,一点一点地焕然一新 #####
  • 相关阅读:
    Linux 磁盘分区
    curl
    Metasploit ms10_046_shortcut_icon_dllloader 利用
    Ettercap 入门
    Ettercap dos_attack
    Centos7/Debian 配置双网卡
    Centos7配置单网卡,多IP
    Ettercap MITM Arp Poisoning
    Ettercap DNS Spoofing
    java常用设计模式--工厂模式简单例子
  • 原文地址:https://www.cnblogs.com/johnyang/p/13167149.html
Copyright © 2011-2022 走看看