diff --git a/memcache.py b/memcache.py index 9823a2f..29f7946 100644 --- a/memcache.py +++ b/memcache.py @@ -1330,6 +1330,9 @@ def check_key(self, key, key_extra_len=0): "Control/space characters not allowed (key=%r)" % key) +_host_last_deaduntils = {} + + class _Host(object): def __init__(self, host, debug=0, dead_retry=_DEAD_RETRY, @@ -1371,7 +1374,7 @@ def __init__(self, host, debug=0, dead_retry=_DEAD_RETRY, self.port = int(hostData.get('port') or 11211) self.address = (self.ip, self.port) - self.deaduntil = 0 + self.deaduntil = _host_last_deaduntils.get(self.ip, 0) self.socket = None self.flush_on_next_connect = 0 @@ -1382,8 +1385,11 @@ def debuglog(self, str): sys.stderr.write("MemCached: %s\n" % str) def _check_dead(self): - if self.deaduntil and self.deaduntil > time.time(): - return 1 + if self.deaduntil: + if self.deaduntil > time.time(): + return 1 + else: + _host_last_deaduntils[self.ip] = 0 self.deaduntil = 0 return 0 @@ -1411,6 +1417,7 @@ def _get_socket(self): s.connect(self.address) except socket.timeout as msg: self.mark_dead("connect: %s" % msg) + _host_last_deaduntils[self.ip] = self.deaduntil return None except socket.error as msg: if isinstance(msg, tuple):