2016-02-25 22 views
10

Tôi đang cố gắng tìm ra cách để thiết lập thời gian chờ kết nối trong create_engine(), cho đến nay tôi đã cố gắng:Làm thế nào để thiết lập thời gian chờ kết nối trong SQLAlchemy

create_engine(url, timeout=10) 

TypeError: Invalid argument(s) 'timeout' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

create_engine(url, connection_timeout=10) 

TypeError: Invalid argument(s) 'connection_timeout' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

create_engine(db_url, connect_args={'timeout': 10}) 

(psycopg2.OperationalError) invalid connection option "timeout"

create_engine(db_url, connect_args={'connection_timeout': 10}) 

(psycopg2.OperationalError) invalid connection option "connection_timeout"

create_engine(url, pool_timeout=10) 

Tôi nên làm gì?

Trả lời

19

Cách đúng là cái này (connect_timeout thay vì connection_timeout):

create_engine(db_url, connect_args={'connect_timeout': 10}) 

... và nó hoạt động với cả hai Postgres và MySQL

+2

là gì giá trị mặc định cho biến connect_timeout (nói chung và cụ thể cho cơ sở dữ liệu MySQL? – nivhanin

Các vấn đề liên quan