如何在SQLAlchemy中设置连接超时 [英] How to set connection timeout in SQLAlchemy

查看:1981
本文介绍了如何在SQLAlchemy中设置连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出如何在 create_engine()中设置连接超时,到目前为止,我已经尝试过:

  create_engine(url,timeout = 10)



< blockquote>

TypeError:使用配置PGDialect_psycopg2 / QueuePool / Engine将无效的参数超时发送到create_engine()。请检查
关键字参数是否适合此
组件组合。




  create_engine(url,connection_timeout = 10)




TypeError:使用配置
PGDialect_psycopg2 / QueuePool / Engine将无效的参数'connection_timeout'发送到
create_engine()。请检查关键字
参数是否适合此组件组合。




  create_engine(db_url,connect_args = {'timeout':10})




(psycopg2.OperationalError)无效的连接选项
超时




  create_engine(db_url ,connect_args = {'connection_timeout':10})




(psycopg2。 OperationalError)无效的连接选项
connection_timeout




  create_engine(url,pool_timeout = 10)

我该怎么办?

解决方案

正确的方法是以下方法( connect_timeout 而不是 connection_timeout ):

  create_engine(db_url,connect_args = {'connect_timeout':10})

...并且与Postgre一起使用s和MySQL



ps :(超时以秒为单位)


I'm trying to figure out how to set the connection timeout in create_engine(), so far I've tried:

create_engine(url, timeout=10)

TypeError: Invalid argument(s) 'timeout' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

create_engine(url, connection_timeout=10)

TypeError: Invalid argument(s) 'connection_timeout' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

create_engine(db_url, connect_args={'timeout': 10})

(psycopg2.OperationalError) invalid connection option "timeout"

create_engine(db_url, connect_args={'connection_timeout': 10})

(psycopg2.OperationalError) invalid connection option "connection_timeout"

create_engine(url, pool_timeout=10)

What should I do?

解决方案

The right way is this one (connect_timeout instead of connection_timeout):

create_engine(db_url, connect_args={'connect_timeout': 10})

...and it works with both Postgres and MySQL

ps: (the timeout is defined in seconds)

这篇关于如何在SQLAlchemy中设置连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆