3

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.

2 Answers 2

4

command_timeout is set only on application level. It means query will still be running in database after timeout error in your application. To set timeout on database level you should use server_settings:

create_async_engine(
    db_url, connect_args={"server_settings": {"statement_timeout": "10000"}},
)
Sign up to request clarification or add additional context in comments.

Comments

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

use command_timeout in connect_args in seconds

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.