From 979bbe97e11fd8717af8c9f54d26906d30262a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 14 Jun 2020 19:59:44 +0200 Subject: [PATCH] add timeout to index_request --- sdbs_infra/dashboard/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdbs_infra/dashboard/models.py b/sdbs_infra/dashboard/models.py index 6754489..d10bdd2 100644 --- a/sdbs_infra/dashboard/models.py +++ b/sdbs_infra/dashboard/models.py @@ -1,5 +1,6 @@ import urllib.request from enum import Enum +from socket import timeout from urllib.error import URLError from urllib.request import Request @@ -28,8 +29,8 @@ class Service(OrderedModel): def index_request(self): try: request = Request(self.url, headers={'User-Agent': 'its just me humble status page'}) - return urllib.request.urlopen(request) - except URLError: + return urllib.request.urlopen(request, timeout=1) + except (URLError, timeout): return None def get_status(self):