def mutithread_query(self, sql_format, res_file_name): sqls = self.get_sql(sql_format) res_file = open(res_file_name, "a") thread_id = 0 for conn_data in self.connect_info: thread_list = [] for sql in sqls: connectInfo = dbOper.conn_db(conn_data) thread_id += 1 thread_list.append( threading.Thread(target=self.qry, args=(sql, res_file, connectInfo), name=thread_id)) time.sleep(0.05) logger.info("线程装载完毕,开始执行") for thread in thread_list: thread.start() logger.info("%s 线程开始", thread.name) for thread in thread_list: thread.join() time.sleep(0.005) self.logger.error("Query finished") logger.error("计数:" + str(self.count)) time.sleep(10) print "本组执行完毕,累计%s个sql" % thread_id
def getPhoneFile(self, ): phone_file = self.phone_dir + str(os.sep) + self.phoneFileName if os.path.exists(r'%s' % (phone_file)): print "号码文件:%s" % phone_file logger.info("号码文件已经生成,请注意是否需要重新生成,号码文件:%s" % phone_file) else: conn_data = dataBase logger.info("开始连接数据库") try: cur, conn = dbOper.conn_db(conn_data) # 获取数据库连接cur logger.info("连接数据库成功") except Exception as e: logger.info("连接数据库失败") try: sql = self.getSql() logger.info("Query starting with sql : " + sql) head, result = dbOper.qryData(cur, sql) logger.info("Query end ") logger.info('开始生成号码文件') try: with open(phone_file, "a") as phoneFile: for res in result: phoneFile.write(",".join(map(str, res))) phoneFile.write("\n") except Exception as e: print e print "号码文件生成结束:%s" % phone_file phoneFile.close() except Exception as e: print("查询数据失败") return phone_file
def getConnect(): try: cur1, conn1 = dbOper.conn_db(config.kqzx2_0_1) logger.info("连接数据库1成功") except Exception as e: logger.error("连接数据库1失败") cur1, conn1 = None, None try: cur2, conn2 = dbOper.conn_db(config.kqzx2_0_2) logger.info("连接数据库2成功") except Exception as e: logger.error("连接数据库2失败") cur2, conn2 = None, None cur = [cur1, cur2] conn = [conn1, conn2] return cur, conn
def getConnect(): try: cur, conn = dbOper.conn_db(config.ecora) logger.info("连接数据库成功") except Exception as e: logger.info(e) logger.error("连接数据库失败") cur, conn = None, None return cur, conn
def getPhoneFile(): conn_data = dataBase try: print '开始连接数据库' cur, conn = dbOper.conn_db(conn_data) # 获取数据库连接cur print '连接数据库成功' logger.info('连接数据库成功') print platform.python_version() except Exception as e: print '连接数据库失败:' print e print platform.python_version() logger.info('连接数据库失败') logger.info(e)
def getPhoneFile(self): phone_file = '%s/%s.dat' % (self.resData, self.phoneFileName) logger = self.logger if os.path.exists(r'%s' % (phone_file)): print '号码文件已经生成,请注意是否需要重新生成' print "号码文件:%s" % phone_file logger.info("号码文件已经生成,请注意是否需要重新生成") print "sql is:" + self.getSql() else: conn_data = dataBase optSeq = self.getOptSeq() # print conn_data # 调用数据库连接模块,生成数据库连接cur print '开始连接数据库' logger.info("开始连接数据库") try: cur, conn = dbOper.conn_db(conn_data) # 获取数据库连接cur print '连接数据库成功:' print cur, conn logger.info("连接数据库成功") except Exception as e: print("连接数据库失败") print e logger.info("连接数据库失败") logger.info(e) try: sql = self.getSql() logger.info("sql is" + sql) print 'getSql()\'s result :' + sql print "查询开始" + sql, self.pcardName head, result = dbOper.qryData(cur, sql) print "查询完成" # 写号码文件 print '开始生成号码文件' with open(phone_file, "a") as phoneFile: for res in result: print(res) print(type(res)) phoneFile.write("%s,%s,%s" % (res[0], res[1], optSeq)) phoneFile.write("\n") print "号码文件生成结束:%s" % phone_file phoneFile.close() except Exception as e: print("查询数据失败") return '%s/%s' % (self.resData, self.phoneFileName)