sqlalchemy和asyncpg–设置postgres statement_timeout
做的时候
engine: AsyncEngine = create_async_engine(...)
在这样
async with engine.connect() as conn:
result: Result = await conn.execute(text("""..."""))
,我想指定超时。理想情况下,我能够设置仅用于此查询执行。我对Sqlalchemy进行超时并取消查询执行我也很好,但是我找不到设置的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在几秒钟内使用command_timeout in connect_args
use command_timeout in connect_args in seconds
command_timeout
仅在应用程序级别上设置。这意味着在应用程序中的超时错误之后,查询仍将在数据库中运行。要在数据库级别设置超时,您应该使用server_settings
: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 useserver_settings
: