Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分图色 函数在pyside6中QThread,使用terminate强制停止子线程,并重新启动后报错 #140

Open
XYZZ-404 opened this issue May 11, 2024 · 3 comments

Comments

@XYZZ-404
Copy link

XYZZ-404 commented May 11, 2024

屏幕截图 2024-05-11 082741

简单的复现代码:

`from win32com.client import Dispatch
op = Dispatch("op.opsoft")
import sys
from PySide6.QtCore import QThread
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton

class WorkerThread(QThread):

def __init__(self):
    super().__init__()
    self.op = op

def run(self):
    for i in range(100):
        cmp_color = self.op.CmpColor(0, 0, "ffffff", 1)
        self.op.Delay(1000)
        print(cmp_color)
    self.finished.emit()

class MainWindow(QWidget):
def init(self):
super().init()
self.initUI()

def initUI(self):
    layout = QVBoxLayout()
    self.startButton = QPushButton('Start Thread', self)
    self.stopButton = QPushButton('Kill Thread', self)
    self.startButton.clicked.connect(self.startThread)
    self.stopButton.clicked.connect(self.killThread)
    layout.addWidget(self.startButton)
    layout.addWidget(self.stopButton)
    self.setLayout(layout)

def startThread(self):
    print("Starting thread...")
    self.thread = WorkerThread()
    self.thread.start()

def killThread(self):
    print("Killed thread...")
    self.thread.terminate()

if name == 'main':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())

`
这段代码在启动后,第一次启停线程时正常运行,第二次启动时,每次试图调用cmpcolor都会弹窗
目前测试结果,findcolor,cmpcolor,getcolor均会报错,而其他类别的函数如keypress等不会报错

@XYZZ-404 XYZZ-404 changed the title CmpColor 函数在pyside6中QThread,使用terminate强制停止子线程,并重新启动后报错 部分图色 函数在pyside6中QThread,使用terminate强制停止子线程,并重新启动后报错 May 11, 2024
@XYZZ-404
Copy link
Author

使用的是Pycharm + python 3.12 64位, op-0.4.5 64位免注册版

@XYZZ-404
Copy link
Author

刚才又测试了一下,在不使用terminate命令终止线程后,下次调用依然会出现一样的问题

@XYZZ-404
Copy link
Author

使用deletelater()命令能够避免这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant