Skip to content

Commit

Permalink
[优化]tqdm
Browse files Browse the repository at this point in the history
  • Loading branch information
longfengpili committed Nov 3, 2023
1 parent 9ff830a commit 62d0262
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pydbapi/api/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2023-11-03 10:56:03
# @Last Modified time: 2023-11-03 14:25:59
# @github: https://github.com/longfengpili


Expand Down Expand Up @@ -121,9 +121,9 @@ def __init__(self, host, user, password, database, port=3306, charset="utf8", sa

@classmethod
def get_instance(cls, *args, **kwargs):
mysqllogger.info(MysqlDB._instance_lock)
# mysqllogger.info(MysqlDB._instance_lock)
if not hasattr(MysqlDB, '_instance'):
mysqllogger.info(MysqlDB._instance_lock)
# mysqllogger.info(MysqlDB._instance_lock)
with MysqlDB._instance_lock:
if not hasattr(MysqlDB, '_instance'):
MysqlDB._instance = cls(*args, **kwargs)
Expand Down
15 changes: 10 additions & 5 deletions pydbapi/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2023-11-03 10:52:50
# @Last Modified time: 2023-11-03 17:21:26
# @github: https://github.com/longfengpili


import re
import sys
import pandas as pd
from tqdm import tqdm

from pydbapi.sql import SqlParse, SqlCompile
from pydbapi.conf import AUTO_RULES
Expand Down Expand Up @@ -76,7 +76,12 @@ def execute(self, sql, count=None, ehandling='raise', verbose=0):
# results = list(results) if results else []
# columns = tuple(map(lambda x: x[0].lower(), cur.description)) if cur.description # 列名
# return columns, results


if any("jupyter" in arg for arg in sys.argv):
from tqdm.notebook import tqdm
else:
from tqdm import tqdm

rows = 0
idx = 0
conn = self.get_conn()
Expand All @@ -86,8 +91,8 @@ def execute(self, sql, count=None, ehandling='raise', verbose=0):
# print(sqls)
sqls = [sql.strip() for sql in sqls if sql]
sqls_length = len(sqls)
bar_format = '{l_bar}{bar:30}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}] {postfix[0]}'
sqls = sqls if verbose <= 1 else tqdm(sqls, ncols=100, postfix=['START'], bar_format=bar_format) # 如果verbose>=2则显示进度条
bar_format = '{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}] {postfix[0]}'
sqls = sqls if verbose <= 1 else tqdm(sqls, postfix=['START'], bar_format=bar_format) # 如果verbose>=2则显示进度条
for _sql in sqls:
results = None
idx += 1
Expand Down

0 comments on commit 62d0262

Please sign in to comment.