-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Can you check the operation of the "timeout" parameter?
I get a strange delay with throwing an exception when changing the parameter:engine = sa.create_engine(cons, echo=False) =>
error ["Server not available, exception: HTTPConnectionPool(host='crate.airflow.local', port=4201): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x00000180F5662F10>, 'Connection to crate.airflow.local timed out. (connect timeout=None)'))"]
Elapsed time: 0:03:52.292546engine = sa.create_engine(cons, echo=False, connect_args={"timeout": 1}) =>
error ["Server not available, exception: HTTPConnectionPool(host='crate.airflow.local', port=4201): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x000001EA64912F10>, 'Connection to crate.airflow.local timed out. (connect timeout=1)'))"]
Elapsed time: 0:00:11.255726engine = sa.create_engine(cons, echo=False, connect_args={"timeout": 2})
error ["Server not available, exception: HTTPConnectionPool(host='crate.airflow.local', port=4201): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x000001F525D72F10>, 'Connection to crate.airflow.local timed out. (connect timeout=2)'))"]
Elapsed time: 0:00:22.450192Connection timeouts (in seconds) can be configured with the optional timeout argument: connection = client.connect(..., timeout=5)import sys import sqlalchemy as sa from sqlalchemy.exc import SQLAlchemyError from datetime import datetime cons = "crate://user:[email protected]:4201?ssl=false" start = datetime.now() try: engine = sa.create_engine(cons, echo=False, connect_args={"timeout": 2}) connection = engine.connect() print("success connect to DB") except SQLAlchemyError as err: print("error", err.__cause__) # this will give what kind of error print("Elapsed time:", datetime.now() - start) sys.exit(1) # we have connection, let's get data tables = connection.execute(sa.text("SHOW TABLES;")).all() print(tables)