我试图在btnclicked_2()中同时运行几个函数“stavka”。获取错误:
(<class 'TypeError'>, TypeError("cannot pickle 'mywindow' object"), <traceback object at 0x000000B2CF1C6240>)
(<class 'EOFError'>, EOFError('Ran out of input'), <traceback object at 0x0000009EB6DDC9C0>)
我知道我不能使用self作为参数,但我需要它在这个函数中。不知道该怎么办。也许我做错了什么,或者根本不可能,请帮忙。
def stavka(self, AuctionID_raw, Price, data3, AuctionID, place):
while True:
.
.
.
def btnClicked(self):
.
.
.
def btnCkicked_2(self):
if __name__ == '__main__':
proc = Process(target=self.stavka ,args=(AuctionID_raw, Price, data3, AuctionID, place,))
procs[place] = proc
proc.start()
使用多线程
class Worker(QObject):
finished = pyqtSignal()
def run(self, AuctionID_raw, Price, data3, AuctionID, place):
while True:
login = self.lineEdit.text()
.
.
.
class mywindow(QtWidgets.QMainWindow):
def __init__(self):
super(mywindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.btnClicked)
self.ui.pushButton_2.clicked.connect(self.btnCkicked_2)
self.ui.pushButton_3.clicked.connect(self.btnCkicked_3)
def btnCkicked_2(self):
.
.
.
self.thread = QThread()
self.worker = Worker()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.run(AuctionID_raw, Price, data3, AuctionID, place))
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()
1条答案
按热度按时间gcmastyq1#
您尝试使用多处理调用插槽,这是不可能的,因为gui位于一个进程中,多处理模块尝试但失败了:它尝试使用pickle序列化窗口(这没有多大意义-小部件不可复制且不可序列化),生成另一个进程并将其传递给该进程,这就更没有意义了。
只需使用多线程,继承
QThread
,将函数放入run()
方法与start()
它从主线程开始。