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连接器-建立数据库连接的时间


猜你喜欢
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 沿轴计算直方图 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01