Avoid divide-by-zero when all hosts are down

This commit is contained in:
Tyler Hobbs
2013-05-02 17:36:29 -05:00
parent e6167d2cab
commit bd26be15f0

View File

@@ -40,8 +40,11 @@ class RoundRobinPolicy(LoadBalancingPolicy):
self._position += 1
length = len(self._live_hosts)
pos %= length
return islice(cycle(self._live_hosts), pos, pos + length)
if length:
pos %= length
return islice(cycle(self._live_hosts), pos, pos + length)
else:
return []
def on_up(self, host):
self._live_hosts.add(host)