summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <ford_prefect@gentoo.org>2009-03-09 00:29:34 +0530
committerArun Raghavan <ford_prefect@gentoo.org>2009-03-09 00:29:34 +0530
commit02800a8fa14dffa2cf122ebc87842d67134f521b (patch)
tree1d036647134efdfb20ebfccbf30452fc3c362ba1
parentCosmetic changes to messages (diff)
downloadgard-02800a8fa14dffa2cf122ebc87842d67134f521b.tar.gz
gard-02800a8fa14dffa2cf122ebc87842d67134f521b.tar.bz2
gard-02800a8fa14dffa2cf122ebc87842d67134f521b.zip
Add a timeout for http/ftp connections
urllib2 doesn't support specifying a timeout, so we set a global timeout using the socket class.
-rw-r--r--check.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/check.py b/check.py
index fba550b..0f6aebb 100644
--- a/check.py
+++ b/check.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
import logging
+import socket
import urllib2
import time
import rfc822
@@ -12,13 +13,17 @@ import urlparse
class GardCheck:
# Base class which provides some helper functions
- def __init__(self, url, log=True):
+ def __init__(self, url, log=True, timeout=30):
self.url = url
if log:
self.logger = logging.getLogger('')
else:
self.logger = None
+ # By default urllib2 has no timeout, so we need to set a sane
+ # global maximum
+ socket.setdefaulttimeout(timeout)
+
def log_info(self, msg):
if self.logger is not None:
self.logger.info(msg)