现象:PYQT5+PY3.6开发,生成执行exe闪退,无异常就提示Process finished with exit code -1073741819 (0xC0000005)
代码:
# TCPclient按钮
def clientmain(self):
try:
# 主机地址
if self.comboBoxchose_TCP.currentText()=="TCPClient":
global toSend,IP,SERVER_PORT,dataSocket,BUFLEN,toSendSet
IP = str(self.lineEditsd_TCPIP.text())
SERVER_PORT = int(self.lineEditsd_TCPDK.text())
BUFLEN =1024
# 实例化对象
dataSocket = socket(AF_INET, SOCK_STREAM)
dataSocket.connect((IP, SERVER_PORT))
global t1
if t1 in threads:
stop_thread(t1)
threads.remove(t1)
if self.pushButtonclr_TCP.text() == "连接":
self.pushButtonclr_TCP.setText("断开")
toSend= toSendSet
t1 = threading.Thread(target=self.dataSocket_recv, args=(toSend,))
t1.start()
threads.append(t1)
else:
toSend=""
dataSocket.close()
self.pushButtonclr_TCP.setText("连接")
except Exception as e:
print(e)
open("./数据/err.txt", 'w+', encoding='utf-8').write(traceback.format_exc())
# TCP数据处理
def dataSocket_recv(self,toSend):
try:
global IP, SERVER_PORT, dataSocket,BUFLEN,rizhi,RIZHIWJM
global num
global t1
num=0
while True:
if toSend!="":
dataSocket.send(toSend.encode('utf8'))
#time.sleep(10)
out_s=toSend
out_s += '\r\n'
global rizhi, RIZHIWJM
if rizhi == "True":
with open(RIZHIWJM, "a+", encoding="utf-8", errors='ignore') as f:
f.writelines(out_s)
f.flush()
# print("循环发送数据out_s")
# self.plainTextEdit.insertPlainText(out_s)
self.plainTextEdit.appendPlainText(out_s)
# 获取到text光标
# print("获取到text光标")
textCursor = self.plainTextEdit.textCursor()
# 滚动到底部
# print("滚动到底部")
textCursor.movePosition(textCursor.End)
# 设置光标到text中去
# print("设置光标到text中去")
self.plainTextEdit.setTextCursor(textCursor)
# print("设置plainTextEdit")
toSend = ""
recved = dataSocket.recv(BUFLEN)
if not recved:
pass
if self.pushButtonclr_TCP.text() == "连接":
dataSocket.close()
break
time.sleep(0.7)
#print(recved.decode('gbk', errors='ignore'))
if rizhi == "True":
with open( RIZHIWJM, "a+", encoding="gbk", errors='ignore') as f:
f.writelines(recved.decode('gbk', errors='ignore'))
f.flush()
self.plainTextEdit.appendPlainText(recved.decode('gbk', errors='ignore'))
num = len(recved)
self.data_num_received += num
if self.data_num_received > 1048576:
self.plainTextEdit.clear()
self.data_num_received = 0
self.data_num_sended = 0
# time.sleep(0.5)
# 获取到text光标
textCursor = self.plainTextEdit.textCursor()
# 滚动到底部
textCursor.movePosition(textCursor.End)
# 设置光标到text中去
self.plainTextEdit.setTextCursor(textCursor)
#dataSocket.close()
if t1 in threads:
stop_thread(t1)
threads.remove(t1)
except Exception as e:
print(e)
open("./数据/err.txt", 'w+', encoding='utf-8').write(traceback.format_exc())
求各位同行指教,EXE闪退时间不一定,不好分析也没有抓取到异常。