Received error分段错误(core dump)



我编写了一个程序,它将从相机中获取日志,解析每一行,以查看我创建的文件中的日志是否在日志行中,如果是,则计算正确的日志被触发的次数。

from collections import deque
import sys
import os
from threading import Thread
from time import sleep
sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname('../'))))
from livelogparser.clientlogParser import ClientLogParser 
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QThread, QObject
from PyQt5.QtGui import QTextCursor
ON_POSIX = 'posix' in sys.builtin_module_names
class Ui_logWindow(object):
def logs(self):
arg1 = self.lineEdit.text()
arg2 = int(self.lineEdit_2.text())
arg3 = self.lineEdit_3.text()
arg4 = self.lineEdit_4.text()
arg5 = self.lineEdit_5.text()
arg6 = self.lineEdit_6.text()
self.q = deque()
#on_message comes from ClientLogParser class
self.client = ClientLogParser(arg1, arg2, arg3, arg4, arg5, arg6)
self.client.client.on_message = self.onMsgWin
#startListen is loop_forever()
self.t = Thread(target=self.client.startListen, args=[])
self.t.daemon = True
self.t.start()
def onMsgWin(self, client, userdata, msg):
self.listMsg = msg.payload.decode('utf-8').rstrip()
self.textEdit.append(self.listMsg)
self.textEdit.moveCursor(QTextCursor.End)
for line in self.listMsg.split('n'):
self.client.lp.parseEvent(line)
self.q.append(line)
if len(self.q) < 20:
output_GUI = ''
for line in self.q:
self.client.rp.evaluateDict(self.client.lp.dictLogs)
output_GUI += "COUNT:n"
for key, val in self.client.lp.dictLogs.items():
output_GUI += f"EVT[{key}] COUNT[{val}]n"
if val > 0:
output_GUI += f'------ the event : {key} has been triggered ------n'
output_GUI += "RULES:n"
for rule_idx in range(len(self.client.rp.dictRulesList)):
if self.client.rp.resultList[rule_idx] == 'critical':
sys.exit(-1)
if self.client.rp.resultList[rule_idx] == 'warning':
output_GUI += '----------succes----------n'
if self.client.rp.resultList[rule_idx] == 'info':
output_GUI += '----------succes----------n'
if self.client.rp.resultList[rule_idx] == 'succes':
output_GUI += '----------succes----------n'
output_GUI += f"RULE:[{rule_idx}][{self.client.rp.dictRulesList[rule_idx]}]n"
output_GUI += f"RESULT[{rule_idx}][{self.client.rp.resultList[rule_idx]}]n"
output_GUI += "----ITERATION-END----n"
self.textEdit_2.append(output_GUI)
self.textEdit_2.moveCursor(QTextCursor.End)
else:
sleep(5)
self.q.clear()
continue

问题是,有时程序正在工作,它在textEdit_2中打印我需要的东西,有时它会崩溃,错误;分割错误(核心转储)">

我试着做一个队列,这将需要20行(因为日志行来的非常快,像30-40在3-4秒),解析它们并将它们添加到editText_2,睡眠5秒,然后再做一次,但结果是相同的。edit_Text是附加每一个日志线,因为它是从相机。有人能帮帮我吗?

我解决了这个问题。如果有人有这个问题:在从日志中读取的行之前放一个sleep(.1)可能会有所帮助:

def onMsgWin(self, client, userdata, msg):
self.listMsg = msg.payload.decode('utf-8').rstrip()
self.textEdit.append(self.listMsg)
self.textEdit.moveCursor(QTextCursor.End)
for line in self.listMsg.split('n'):
sleep(.1)
self.client.lp.parseEvent(line)`

最新更新