相关疑难解决方法(0)

使用sqlalchemy create_engine配置查询/命令超时?

以下Python代码段说明了此问题:

print("starting")

# I am trying to configure a query/command timeout of one second.
# sqlalchemy docs suggest execution_options but the documented list of options doesn't include a timeout:
# http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Connection.execution_options
# Below, I am guessing at several likely timeout parameter names:
db_engine = create_engine("postgresql://user:pass@server/catalog",
                          execution_options={"timeout": 1.0,
                                             "statement_timeout": 1.0,
                                             "query_timeout": 1.0,
                                             "execution_timeout": 1.0})

with db_engine.connect() as db_connection:
    print("got db_connection")

    # Artificially force a two second query time with pg_sleep.
    # This is designed to guarantee timeout conditions and trigger an …
Run Code Online (Sandbox Code Playgroud)

python postgresql sqlalchemy

4
推荐指数
1
解决办法
4617
查看次数

标签 统计

postgresql ×1

python ×1

sqlalchemy ×1