diff options
author | 2009-03-09 00:29:34 +0530 | |
---|---|---|
committer | 2009-03-09 00:29:34 +0530 | |
commit | 02800a8fa14dffa2cf122ebc87842d67134f521b (patch) | |
tree | 1d036647134efdfb20ebfccbf30452fc3c362ba1 | |
parent | Cosmetic changes to messages (diff) | |
download | gard-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.py | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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) |