python - Django - using thread.start_new_thread for reading a file throws exception while "simplejson.loads" -
i have log file, have parse. log file may have 3 types of lines
cat- xxxxxxxxxxxxx dog - xxxxxxxxxxxxxxx rat - xxxxxxxxxxxxx
my parse function in python script
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') 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
now when code reached line 1 throws exception
'nonetype' object has no attribute 'loads'
i know simplejson has been deprecated in present version of django, m using older version.
Comments
Post a Comment