snowflake python connector - Time to make database connection(雪花Python连接器-建立数据库连接的时间)
本文介绍了雪花Python连接器-建立数据库连接的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python代码大约需要2-3秒来建立雪花数据库连接。这是意料之中的行为吗?或者是否有任何参数可以加快连接时间。
示例代码如下:
import snowflake.connector
import time
t1=time.time()
print("Start time :"+str(t1))
try:
conn = snowflake.connector.connect(
user=user,
password=password,
account=account,
warehouse=warehouse,
# database=DATABASE,
# schema=SCHEMA
)
cur = conn.cursor()
except Exception as e:
logging.error("Connection Error while initialing connection to snowflake")
logging.error(str(e))
t2=time.time()
print("End time: "+str(t2))
t3=t2-t1
print("Difference(secs) : "+str(t3))
print("DB Connection : END")
tart time :1575009530.075109
End time: 1575009533.320529
Difference(secs) : 3.245419979095459
DB Connection : END
推荐答案
您可能应该关闭雪花记录。默认情况下,您将看到大量控制台信息和调试消息,写入控制台并不是一项简单的操作。
def add_module_handler(logger, level=logging.DEBUG):
"""Module handler for log file.
:param logger: Logger object
:type logger: :class:`logging.Logger`
:param level: Log level to set., defaults to logging.DEBUG
:type level: int, optional
"""
logformat = '[%(asctime)s] %(levelname)s:%(name)s:%(message)s'
logging.basicConfig(level=level,stream=sys.stdout,
format=logformat, datefmt="%Y-%m-%d %H:%M:%S")
if not os.path.exists(path):
os.makedirs('logs')
handler = logging.FileHandler(
f"{path}/module-{logger.name.replace('.', '-')}.log"
)
formatter = logging.Formatter(logformat)
handler.setFormatter(formatter)
handler.setLevel(level)
for name in logging.Logger.manager.loggerDict.keys():
if 'snowflake' or 'urllib3' in name:
logging.getLogger(name).setLevel(logging.ERROR)
logging.getLogger(name).propagate = False
logger.addHandler(handler)
return
这篇关于雪花Python连接器-建立数据库连接的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:雪花Python连接器-建立数据库连接的时间


基础教程推荐
猜你喜欢
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01