Skip to content

Commit 5fd20a9

Browse files
authored
Adding timeout parameter to library. (#13)
1 parent 8e3dea0 commit 5fd20a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

netdata/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
class Netdata(object):
2222
"""A class for handling connections with a Netdata instance."""
2323

24-
def __init__(self, host, port=19999, tls=None, path=None):
24+
def __init__(self, host, port=19999, tls=None, path=None, timeout=5.0):
2525
"""Initialize the connection to the Netdata instance."""
2626
self.host = host
2727
self.port = port
2828
self.values = self.alarms = self.metrics = None
29+
self.timeout = timeout
2930

3031
self.scheme = "http" if tls is None or not False else "https"
3132

@@ -42,7 +43,7 @@ async def get_data(self, url) -> Dict:
4243
"""Execute a request to a data endpoint."""
4344
try:
4445
async with httpx.AsyncClient() as client:
45-
response = await client.get(str(url))
46+
response = await client.get(str(url), timeout = self.timeout)
4647
except httpx.ConnectError:
4748
raise exceptions.NetdataConnectionError(
4849
f"Connection to {self.scheme}://{self.host}:{self.port} failed"

0 commit comments

Comments
 (0)