【问题标题】:sqlalchemy and asyncpg – set postgres statement_timeoutsqlalchemy 和 asyncpg – 设置 postgres statement_timeout
【发布时间】:2022-08-04 22:52:58
【问题描述】:

做的时候

engine: AsyncEngine = create_async_engine(...)

接着

async with engine.connect() as conn:
    result: Result = await conn.execute(text(\"\"\"...\"\"\"))

我想指定一个超时。理想情况下,我可以设置statement_timeout 只是为了执行这个查询。我对 sqlalchemy 执行超时和取消查询执行也很好,但我也找不到设置方法。

    标签: python sqlalchemy python-3.10 postgresql-13 asyncpg


    【解决方案1】:
    create_async_engine(
                db_url, connect_args={"options": "-c command_timeout=28.0"}
            )
    

    以秒为单位在 connect_args 中使用 command_timeout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 2013-03-19
      • 2018-01-04
      • 2015-11-04
      • 2016-12-22
      • 2021-08-21
      • 1970-01-01
      相关资源
      最近更新 更多