I'm trying to figure out how to set the connection timeout in create_engine()
, so far I've tried:
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)
What should I do?
close() method is automatically invoked at the end of the block. The Connection , is a proxy object for an actual DBAPI connection. The DBAPI connection is retrieved from the connection pool at the point at which Connection is created.
SQLAlchemy includes several connection pool implementations which integrate with the Engine . They can also be used directly for applications that want to add pooling to an otherwise plain DBAPI approach.
you call close(), as documented. dispose() is not needed and in fact calling dispose() explicitly is virtually never needed for normal SQLAlchemy usage.
Connection timeout is on the client's side, usually meaning that the client lost connection, or is unable to establish connection to a server for whatever reason (such as remote firewall is dropping the traffic or the server went down).
The right way is this one (connect_timeout
instead of connection_timeout
):
create_engine(db_url, connect_args={'connect_timeout': 10})
...and it works with both Postgres and MySQL
ps: (the timeout is defined in seconds)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With