简体   繁体   English

sqlalchemy 和 asyncpg – 设置 postgres statement_timeout

[英]sqlalchemy and asyncpg – set postgres statement_timeout

When doing做的时候

engine: AsyncEngine = create_async_engine(...)

and then接着

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

I would like to specify a timeout.我想指定一个超时。 Ideally I'd be able to set statement_timeout just for this one query execution.理想情况下,我可以为这个查询执行设置statement_timeout I am also fine with sqlalchemy doing the timeout and cancelling the query execution, but I can't find a way to set either.我对 sqlalchemy 执行超时并取消查询执行也很好,但我也找不到设置方法。

create_async_engine(
            db_url, connect_args={"command_timeout": 28.0}
        )

use command_timeout in connect_args in seconds以秒为单位在 connect_args 中使用 command_timeout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM