pyqt5 使用多线程进行socket通信,界面未响应后程序退出

本来准备开好几个线程通信,写了两个正常运行,加了第三个后界面未响应,pycharm报错Process finished with exit code -1073740791 (0xC0000409)
现在一个线程也这样,不知是哪里出了问题。

这是UI类函数
class TabDemo(QTabWidget,QMainWindow):
def init(self,parent=None):
super(TabDemo,self).__init__(parent)
self.resize(1200,900)
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
self.tab4 = QWidget()
self.tab5 = QWidget()
self.addTab(self.tab1,'Voltage Curent')
self.addTab(self.tab2,'Parameters')
self.addTab(self.tab3,'Waveforms')
self.addTab(self.tab4,'Charts')
self.addTab(self.tab5,'Save Load')
self.tab1UI()
self.tab2UI()
self.tab3UI()
self.tab4UI()
self.tab5UI()

self.Tcptrans = TcpThread()

self.Tcptrans1 = TcpThread1()

self.Tcptrans2 = TcpThread2()

    self.Tcptrans3 = TcpThread3()

self.Tcptrans.start()

self.Tcptrans1.start()

self.Tcptrans2.start()

    self.Tcptrans3.start()

self.Tcptrans.sinOut.connect(self.display)

self.Tcptrans1.sinOut1.connect(self.display1)

self.Tcptrans2.sinOut2.connect(self.display2)

    self.Tcptrans3.sinOut3.connect(self.display3)
    self.setWindowTitle('电能质量监测系统')

这是tab2UI
def tab2UI(self):
grid = QGridLayout()
grid.setSpacing(10)
l1=QLabel('Parameters')
l2=QLabel('24V Supply')
l3=QLabel('Volts')
l4=QLabel('DSP Temp')
l5=QLabel('Dg.c')
self.t1=QTextBrowser()
self.t2=QTextBrowser()

    self.table=QTableWidget(9,20)
    self.g1=QGraphicsView()
    self.table.setVerticalHeaderLabels(['ReactivePowerA', 'ReactivePowerC', 'ActivePowerA',
                                       'ActivePowerC','CurrentA','CurrentC','THD IA',
                                       'THD IC','Meter ID'])
    '''
    self.l1.setGeometry(QtCore.QRect(190, 10, 101, 16))
    self.l2.setGeometry(QtCore.QRect(50, 30, 91, 16))
    self.l3.setGeometry(QtCore.QRect(170, 60, 72, 15))
    self.l4.setGeometry(QtCore.QRect(50, 130, 72, 15))
    self.l5.setGeometry(QtCore.QRect(170, 170, 72, 15))
    self.t1.setGeometry(QtCore.QRect(30, 50, 111, 31))
    self.t2.setGeometry(QtCore.QRect(30, 160, 111, 31))
    self.table.setGeometry(QtCore.QRect(100, 20, 871, 291))
    '''
    grid.addWidget(l1,1,3)
    grid.addWidget(self.g1,2,0,5,16)
    grid.addWidget(l2,2,17)
    grid.addWidget(self.t1,3,17)
    grid.addWidget(l3,3,18)
    grid.addWidget(l4,4,17)
    grid.addWidget(self.t2,5,17)
    grid.addWidget(l5,5,18)
    grid.addWidget(self.table,6,0,20,21)

    self.tab2.setLayout(grid)

这是槽函数
def display3(self,Meterreading):
for i in range(9):
for j in range(20):
self.Item=QTableWidgetItem('%s' % Meterreading[i,j])
self.table.setItem(i,j,self.Item)
这是定义的子线程类class TcpThread3(QThread):
sinOut3 = pyqtSignal(np.ndarray)
def init(self, parent=None):
super(TcpThread3, self).__init__(parent)
self.working = True
def del(self):
# 线程状态改变与线程终止
self.working = False
self.wait()
def run(self):
if self.working == True:
self.tcp_client_socket2 = socket(AF_INET, SOCK_STREAM)
self.tcp_client_socket2.connect(("127.0.0.1", 6666))
while self.working == True:
self.meg3 = b'\x01\x09\x00\x00\x01\x68\xDD\xB5'
self.tcp_client_socket3.send(self.meg3)
self.recv_data3 = self.tcp_client_socket3.recv(1024)
l3 = list()
l4 = list()
CT = 1
PT = 1
for i in range(3, 723, 2):
temp = self.recv_data3[i:i + 2]
result = struct.unpack('!h', temp)[0]
l3.append(result)
list4 = l3[0:320]
a = np.array(list4).reshape(20, 16)
for i in range(10):
l4.append(a[..., i])
ReactivePowerA = l4[0] * 0.0001 * CT * PT
ReactivePowerC = l4[1] * 0.0001 * CT * PT
ActivePowerA = l4[2] * 0.0001 * CT * PT
ActivePowerC = l4[3] * 0.0001 * CT * PT
CurrentA = l4[4] * 0.01 * CT
CurrentC = l4[5] * 0.01 * CT
THDIA = l4[6] * 0.1
THDIC = l4[7] * 0.1
lastone = (a[..., 8] * 65536 + a[..., 9]) * 0.01
Meterreading = np.vstack((ReactivePowerA,
ReactivePowerC,
ActivePowerA,
ActivePowerC,
CurrentA,
CurrentC,
THDIA,
THDIC,
lastone))
self.sinOut3.emit(Meterreading)
QApplication.processEvents()
self.sleep(1)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问