def fetch_sql(sql=None, res=False, *args): # 这个方法写的真是难用 """ 这个方法感觉真的很难用 :param res: 返回结果形态, True 返回内容,False 返回受影响行 :param sql: :param args: :return: """ if not sql: logger.error("sql is nil") return [] try: con = DB.get_connect() cur = con.cursor() sql_log = sql % args row = cur.execute(sql, args) # 预编译防止sql 注入 con.commit() logger.info('sql: '+sql_log) con.close() if not res: # cur.lastrowid return row else: return list(cur.fetchall()) except Exception, e: sql_log = sql % args logger.error('sql: '+sql_log+', error: '+str(e)) return []
def doWork(index): t = threading.currentThread() try: html = urllib2.urlopen(PERF_TEST_URL).read() except urllib2.URLError, e: logger.error(e) global ERROR_NUM ERROR_NUM += 1
def return_dict(key, value): """ two list to dict :param key: :param value: :return: list(dict, dict) """ try: if len(key) == len(value) and False in [isinstance(i, tuple) for i in value] and False in [isinstance(i, list) for i in value]: return dict(zip(key, value)) else: return [dict(zip(key, r)) for r in value] except Exception, e: logger.error("error,"+str(e)+" Dao input key value is not equal, please check Dao : "+str(key)+str(value)) return {}