以下Python代码段说明了此问题:
print("starting")
# I am trying to configure a query/command timeout of one second.
# sqlalchemy docs suggest execution_options but the documented list of options doesn't include a timeout:
# http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Connection.execution_options
# Below, I am guessing at several likely timeout parameter names:
db_engine = create_engine("postgresql://user:pass@server/catalog",
execution_options={"timeout": 1.0,
"statement_timeout": 1.0,
"query_timeout": 1.0,
"execution_timeout": 1.0})
with db_engine.connect() as db_connection:
print("got db_connection")
# Artificially force a two second query time with pg_sleep.
# This is designed to guarantee timeout conditions and trigger an …Run Code Online (Sandbox Code Playgroud)