Skip to content

Instantly share code, notes, and snippets.

@mr-yoo
Created July 12, 2023 13:29
Show Gist options
  • Save mr-yoo/e61378583212f1efc36ea3546ac0d31c to your computer and use it in GitHub Desktop.
Save mr-yoo/e61378583212f1efc36ea3546ac0d31c to your computer and use it in GitHub Desktop.
Thread 종료 기능 추가
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
from PyQt5.QtCore import QThread
import time
class Worker(QThread):
def run(self):
while True:
if self.isInterruptionRequested(): # 인터럽트 확인
print("terminate")
break
print('lol')
time.sleep(1)
class MyWin(QMainWindow):
def __init__(self):
super().__init__()
self.btn_s = QPushButton("start", self)
self.btn_s.clicked.connect(self.clickStartBtn)
self.btn_e = QPushButton("end", self)
self.btn_e.move(0, 40)
self.btn_e.clicked.connect(self.clickEndBtn)
def clickStartBtn(self):
self.w = Worker()
self.w.start()
def clickEndBtn(self):
self.w.requestInterruption()
app = QApplication([])
w = MyWin()
w.show()
app.exec()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment