Skip to content

Commit d465dda

Browse files
authored
fix: pass configured timeout to HTTP client (#222)
1 parent 2870071 commit d465dda

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
### Features
44
1. [#203](https://github.com/influxdata/influxdb-client-python/issues/219): Bind query parameters
55

6+
### Bug Fixes
7+
1. [#222](https://github.com/influxdata/influxdb-client-python/pull/222): Pass configured timeout to HTTP client
8+
69
## 1.16.0 [2021-04-01]
710

811
### Features
@@ -11,7 +14,7 @@
1114

1215
### Bug Fixes
1316
1. [#206](https://github.com/influxdata/influxdb-client-python/pull/207): Use default (system) certificates instead of Mozilla's root certificates (certifi.where())
14-
1. [#217](https://github.com/influxdata/influxdb-client-python/pull/217): Fixed clone_task function
17+
1. [#217](https://github.com/influxdata/influxdb-client-python/pull/217): Fix clone_task function
1518

1619
### API
1720
1. [#209](https://github.com/influxdata/influxdb-client-python/pull/209): Allow setting shard-group durations for buckets via API

influxdb_client/client/influxdb_client.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
class InfluxDBClient(object):
2121
"""InfluxDBClient is client for InfluxDB v2."""
2222

23-
def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org: str = None,
23+
def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, org: str = None,
2424
default_tags: dict = None, **kwargs) -> None:
2525
"""
2626
Initialize defaults.
2727
2828
:param url: InfluxDB server API url (ex. http://localhost:8086).
2929
:param token: auth token
3030
:param debug: enable verbose logging of http requests
31-
:param timeout: default http client timeout
31+
:param timeout: HTTP client timeout setting for a request specified in milliseconds.
32+
If one number provided, it will be total request timeout.
33+
It can also be a pair (tuple) of (connection, read) timeouts.
3234
:param enable_gzip: Enable Gzip compression for http requests. Currently only the "Write" and "Query" endpoints
3335
supports the Gzip compression.
3436
:param org: organization name (used as a default in query and write API)
@@ -43,7 +45,6 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
4345
"""
4446
self.url = url
4547
self.token = token
46-
self.timeout = timeout
4748
self.org = org
4849

4950
self.default_tags = default_tags
@@ -59,6 +60,7 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
5960
conf.ssl_ca_cert = kwargs.get('ssl_ca_cert', None)
6061
conf.proxy = kwargs.get('proxy', None)
6162
conf.connection_pool_maxsize = kwargs.get('connection_pool_maxsize', conf.connection_pool_maxsize)
63+
conf.timeout = timeout
6264

6365
auth_token = self.token
6466
auth_header_name = "Authorization"

influxdb_client/configuration.py

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def __init__(self):
103103
# requests to the same host, which is often the case here.
104104
# cpu_count * 5 is used as default value to increase performance.
105105
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
106+
# Timeout setting for a request. If one number provided, it will be total request timeout.
107+
# It can also be a pair (tuple) of (connection, read) timeouts.
108+
self.timeout = None
106109

107110
# Proxy URL
108111
self.proxy = None

influxdb_client/rest.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ def request(self, method, url, query_params=None, headers=None,
156156
headers = headers or {}
157157

158158
timeout = None
159-
if _request_timeout:
160-
if isinstance(_request_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
161-
timeout = urllib3.Timeout(total=_request_timeout)
162-
elif (isinstance(_request_timeout, tuple) and
163-
len(_request_timeout) == 2):
159+
_configured_timeout = _request_timeout or self.configuration.timeout
160+
if _configured_timeout:
161+
if isinstance(_configured_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
162+
timeout = urllib3.Timeout(total=_configured_timeout / 1_000)
163+
elif (isinstance(_configured_timeout, tuple) and
164+
len(_configured_timeout) == 2):
164165
timeout = urllib3.Timeout(
165-
connect=_request_timeout[0], read=_request_timeout[1])
166+
connect=_configured_timeout[0] / 1_000, read=_configured_timeout[1] / 1_000)
166167

167168
if 'Content-Type' not in headers:
168169
headers['Content-Type'] = 'application/json'

tests/test_InfluxDBClient.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def assertConfig(self):
6565
self.assertEqual("http://localhost:8086", self.client.url)
6666
self.assertEqual("my-org", self.client.org)
6767
self.assertEqual("my-token", self.client.token)
68-
self.assertEqual(6000, self.client.timeout)
68+
self.assertEqual(6000, self.client.api_client.configuration.timeout)
6969
self.assertEqual(3, len(self.client.default_tags))
7070
self.assertEqual("132-987-655", self.client.default_tags["id"])
7171
self.assertEqual("California Miner", self.client.default_tags["customer"])

tests/test_WriteApi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def _check_connection_settings(self):
795795

796796
self.assertEqual("my-org", self.client.org)
797797
self.assertEqual("my-token", self.client.token)
798-
self.assertEqual(6000, self.client.timeout)
798+
self.assertEqual(6000, self.client.api_client.configuration.timeout)
799799

800800
def test_default_tags_from_conf_file(self):
801801
self.client.close()

0 commit comments

Comments
 (0)