Skip to content Skip to sidebar Skip to footer

Configure Query/command Timeout With Sqlalchemy Create_engine?

The following Python code snippet illustrates the issue: print('starting') # I am trying to configure a query/command timeout of one second. # sqlalchemy docs suggest execution_op

Solution 1:

You can set configuration values like statement_timeout via the options parameter in libpq. You can access this parameter in psycopg2 as part of the connect call. You can pass additional parameters to the connect call from SQLAlchemy via the connect_args parameter. So, putting it all together:

engine = create_engine(..., connect_args={"options": "-c statement_timeout=1000"})

Post a Comment for "Configure Query/command Timeout With Sqlalchemy Create_engine?"