简体   繁体   中英

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. I am also fine with sqlalchemy doing the timeout and cancelling the query execution, but I can't find a way to set either.

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

use command_timeout in connect_args in seconds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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