Skip to content

Operation of the "timeout" parameter flawed? #219

Description

@amotl

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.292546

engine = 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.255726

engine = 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.450192

Timeout

Connection 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:a_secret_password@crate.airflow.local: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)

Originally posted by @shraik in #218

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions