crate / crate/sqlalchemy-cratedb
Operation of the "timeout" parameter flawed?
- Dominant language
- Python
- Stars
- 9
- Forks
- 4
- Avg merge
- 6d 12h
- Merged PRs (30d)
- 3
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(, '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(, '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(, 'Connection to crate.airflow.local timed out. (connect timeout=2)'))"]
> **Elapsed time: 0:00:22.450192**
>
> [Timeout](https://cratedb.com/docs/python/en/latest/connect.html#id11)
> ```
> 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](https://github.com/crate/sqlalchemy-cratedb/issues/218#issuecomment-2866900913)_
Contributor guide
Assessment
This issue has not been assessed yet.