1 Star 0 Fork 308

HzGgg / PyQt

forked from PyQt5 / PyQt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
QuitThread.py 941 Bytes
一键复制 编辑 原始数据 按行查看 历史
Irony 提交于 2021-07-13 14:52 . support PySide2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2020/11/27
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
@email: 892768447@qq.com
@file: QuitThread
@description:
"""
import sys
from time import time
try:
from PyQt5.QtCore import QThread, QCoreApplication, QTimer
except ImportError:
from PySide2.QtCore import QThread, QCoreApplication, QTimer
class Thread(QThread):
def run(self):
print('thread id', QThread.currentThread())
i = 0
while i < 101 and not self.isInterruptionRequested():
print('value', i, time())
i += 1
QThread.msleep(500)
print('thread quit')
if __name__ == '__main__':
app = QCoreApplication(sys.argv)
t = Thread()
t.finished.connect(app.quit)
t.start()
# 3秒后退出
print('will quit 3s latter')
QTimer.singleShot(3000, t.requestInterruption)
sys.exit(app.exec_())
Python
1
https://gitee.com/hzggg_small/PyQt.git
git@gitee.com:hzggg_small/PyQt.git
hzggg_small
PyQt
PyQt
master

搜索帮助