Python Django-使用thread.start“u new”线程读取文件时抛出异常,而;simplejson.loads”一词;

Python Django-使用thread.start“u new”线程读取文件时抛出异常,而;simplejson.loads”一词;,python,django,simplejson,Python,Django,Simplejson,我有一个日志文件,我必须解析它。 日志文件可能有3种类型的行 cat- xxxxxxxxxxxxx dog - xxxxxxxxxxxxxxx rat - xxxxxxxxxxxxx 我在python脚本中的解析函数是 from django.utils import simplejson simplejson.JSONEncoder.item_separator = ',' simplejson.JSONEncoder.key_separator = ':' def parseFil

我有一个日志文件,我必须解析它。 日志文件可能有3种类型的行

cat- xxxxxxxxxxxxx
dog - xxxxxxxxxxxxxxx
rat - xxxxxxxxxxxxx
我在python脚本中的解析函数是

from django.utils import simplejson


simplejson.JSONEncoder.item_separator = ','
simplejson.JSONEncoder.key_separator = ':'


def parseFile(self):
     thread.start_new_thread(self.part1,("rat",))
     thread.start_new_thread(self.part1,("dog",))
     thread.start_new_thread(self.part1,("cat",))

def part1(self, tag):
        try:
            print "eating %s feed statements\n"%tag
            log_file = open(self.file,'r')
            for line in log_file:
                    if line.find(tag) != -1:
                            msg = self.getJsonMessage(line)
                            print "hello1"
                            self.META_TAGS[tag](msg)
            log_file.close()
            print "finished eating %s\n"%tag
            print self.positiveCount, self.negcount, self.nocount
        except Exception,e:
            print e


 def getJsonMessage(self,line):
            parts = line.split(' ')
            jsonstr = ''
            count = 4
            while(count<len(parts)):
                    jsonstr += ' ' + parts[count]
                    #print parts[count]
                    count = count + 1
            print jsonstr
            msg = simplejson.loads(jsonstr)        //LINE 1
            date = parts[0].split('-')
            time = parts[1].split(':')
            seconds = time[2].split(',')
            msg['feed_date'] = datetime(int(date[0]),int(date[1]),int(date[2]),int(time[0]),int(time[1]),int(seconds[0]),int(seconds[1]))
            return msg
从django.utils导入simplejson
simplejson.JSONEncoder.item_分隔符=','
simplejson.JSONEncoder.key_分隔符=':'
def解析文件(自身):
线程。启动新线程(self.part1,(“rat”))
线程。开始新线程(self.part1(“dog”))
线程。开始新线程(self.part1(“cat”))
def第1部分(自身,标签):
尝试:
打印“正在吃%s提要语句\n”%tag
log\u file=open(self.file,'r')
对于日志文件中的行:
如果行。查找(标记)!=-1:
msg=self.getJsonMessage(行)
打印“hello1”
self.META_标签[tag](msg)
log_file.close()
打印“已吃完%s\n”%tag
打印self.positiveCount、self.negcount、self.nocount
除例外情况外,e:
打印e
def getJsonMessage(self,行):
零件=直线分割(“”)
jsonstr=''
计数=4

while(count)您还没有显示导入或定义
simplejson
的位置。对不起……让我编辑代码。顺便说一句,如果我不使用线程,此代码可以工作。