Configure query/command timeout with sqlalchemy create_engine?

后端 未结 1 488
眼角桃花
眼角桃花 2020-12-11 06:31

The following Python code snippet illustrates the issue:

print(\"starting\")

# I am trying to configure a query/command timeout of one second.
# sqlalchemy          


        
相关标签:
1条回答
  • 2020-12-11 06:53

    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"})
    
    0 讨论(0)
提交回复
热议问题