From bd26be15f062e7f806d0c2a20ac1385acd18d19f Mon Sep 17 00:00:00 2001 From: Tyler Hobbs Date: Thu, 2 May 2013 17:36:29 -0500 Subject: [PATCH] Avoid divide-by-zero when all hosts are down --- cassandra/policies.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cassandra/policies.py b/cassandra/policies.py index c4c1be84..057193a5 100644 --- a/cassandra/policies.py +++ b/cassandra/policies.py @@ -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)