def thread_getdatalist(self): print("thread_getdatalist") #self.datalist = list() self.datalines = list() self.datalines = func.getBankInfo(self.dataPathVar) print(self.datalines) glob.filelen = len(self.datalines) lineblock = glob.filelen / glob.threadnum print('glob.filelen = %d' % glob.filelen) print('lineblock = %d' % lineblock) if (glob.threadnum > 1): for i in range(glob.threadnum): linenumname = "thread_%d_linestart" % i startline = glob.get_value(linenumname) endline = startline + lineblock - 1 if (endline > glob.filelen): endline = glob.filelen linenumname = "thread_%d_lineend" % i glob.set(linenumname, endline) linenumname = "thread_%d_linestart" % (i + 1) glob.set(linenumname, endline + 1) print("startline = %d" % startline) print("endline = %d" % endline)
def __init__(self, master=None): global bankinfo bankinfo = func.getbankStr() self.URL, self.dataPathVar, self.picpathVar = func.getset() glob._init() glob.set("thread_0_linestart", 0) Application_ui.__init__(self, master)
def stopsend(self): print('stop') print(glob.stopFlag, glob.FFlag) if glob.stopFlag == 1: return glob.stopFlag = 1 if (glob.threadnum == 1): glob.linenum = glob.linenum + glob.linecount + 1 print('linenum = %s' % (glob.linenum)) else: for i in range(glob.threadnum): linenum = glob.get_value("thread_%d_linestart" % i) linecount = glob.get_value("thread_%d_linecount" % i) glob.set("thread_%d_linestart" % i, (linenum + linecount + 1))
def line_init(self): lineblock = glob.filelen / glob.threadnum if glob.filelen % glob.threadnum != 0: lineblock = lineblock + 1 print('glob.filelen = %d' % glob.filelen) print('lineblock = %d' % lineblock) i = int(str(self.threadName).split('_')[1]) print(self.threadName, i) startline = i * lineblock endline = (i+1) * lineblock - 1 if (endline > glob.filelen): endline = glob.filelen print("startline = %d" % startline) print("endline = %d" % endline) linenumname = "thread_%d_linestart" % i glob.set(linenumname, startline) linenumname = "thread_%d_lineend" % i glob.set(linenumname, endline) linenumname = "thread_%d_linecount" % i glob.set(linenumname, 0)
def run(self): print(self.datalines) print("########################################") print(glob.get_value("%s_linestart" % self.threadName)) print(glob.get_value("%s_lineend" % self.threadName)) print("########################################") session = requests.Session() for index, line in enumerate(self.datalines): if glob.stopFlag == 1: return glob.set("%s_linecount" % self.threadName, index) linecount = glob.get_value("%s_linecount" % self.threadName) print("%s = %s" % (("%s_linecount" % self.threadName), linecount)) reqjsonstr = '' info = '' print(line) self.bankinfo['IDNumber'] = line.split(',')[0] self.bankinfo['userName'] = line.split(',')[1] imgName = line.split(',')[2] self.bankinfo['opSerialNum'] = line.split(',')[3] self.bankinfo['img64'] = "" self.bankinfo['img64'] = func.getimg64(self.picpathVar, self.pictypevaluebak, imgName, self.bankinfo, self.returns) bankstr = str(self.bankinfo) self.threadLock.acquire() print(self.threadName,"======",index,"======","字符串长度位%s" % len(str(self.bankinfo))) self.threadLock.release() if self.bankinfo['img64'] == "": outinfo = "%s,请确认图片是否存在或图片格式是否符合要求!!!\n" % (line) self.f_file.w_file(outinfo) continue # req = session.post(self.URL, json=bankinfo, timeout=20) #print(self.bankinfo) req = session.post(self.URL, json=self.bankinfo, timeout=20) #req = requests.post(self.URL, json=self.bankinfo, timeout=20) print("http 请求用时%s" % req.elapsed.total_seconds()) reqjsodict = req.json() print(reqjsodict) reqjsonstr = json.dumps(reqjsodict, sort_keys=True, indent=4, separators=(',', ': '), ensure_ascii=False) self.threadLock.acquire() #info = "进程 %s 第%d条 内容:%s\n" % (self.threadName, (glob.get_value("%s_linestart" % self.threadName) + index + 1), line) info = "进程 %s 第%d条 内容:%s\n" % (self.threadName, (self.startline + index + 1), line) print(info) self.returns.insert(END, info) self.returns.insert(END, reqjsonstr + '\n\n', index) self.returns.see("end") self.threadLock.release() if reqjsodict['resultCode'] != '0000': self.returns.tag_config(index, foreground='red') else: if reqjsodict['checkResult'] == '03': self.returns.tag_config(index, foreground='green') elif reqjsodict['checkResult'] == '12': self.returns.tag_config(index, foreground='yellow') self.returns.update() try: glob.linecount = int(self.returns.index('end-1c').split('.')[0]) print("linecount = %d" % glob.linecount) except: glob.linecount = 0 if (glob.linecount > 50): delcount = '%d.100' % (glob.linecount - 3000) self.returns.delete('1.0', delcount) try: if reqjsodict['resultCode'] != '0000': outinfo = "%s,%s,%s" % (line, reqjsodict["resultCode"], reqjsodict["Reason"]) else: if str(reqjsodict).find("verify") == -1: outinfo = "%s,%s,%s" % (line, reqjsodict["resultCode"], reqjsodict["checkResult"]) else: similarity = reqjsodict["verify"]["similarity"] outinfo = "%s,%s,%s,%s" % ( line, reqjsodict["resultCode"], reqjsodict["checkResult"], similarity) except KeyError: outinfo = "%s,%s" % (line, reqjsodict["resultCode"]) outinfo = "%d,%s" % ((self.startline + index + 1), outinfo) self.f_file.w_file(outinfo + "\n") self.threadLock.acquire() self.line_init() self.threadLock.release()