From ed5a1cce8eddbcd6f18b8cafe95bfd9b33253528 Mon Sep 17 00:00:00 2001 From: Husain Zafar Date: Sun, 19 Feb 2017 16:04:32 +0530 Subject: [PATCH] This commit modifies the elasticsearch/connection_pool.py file to solve the list index out of range error. (#539) Fixes #371 --- elasticsearch/connection_pool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/elasticsearch/connection_pool.py b/elasticsearch/connection_pool.py index 3ec43edf..dbe9a787 100644 --- a/elasticsearch/connection_pool.py +++ b/elasticsearch/connection_pool.py @@ -1,6 +1,7 @@ import time import random import logging +import threading try: from Queue import PriorityQueue, Empty @@ -58,12 +59,12 @@ class RoundRobinSelector(ConnectionSelector): """ def __init__(self, opts): super(RoundRobinSelector, self).__init__(opts) - self.rr = -1 + self.data = threading.local() def select(self, connections): - self.rr += 1 - self.rr %= len(connections) - return connections[self.rr] + self.data.rr = getattr(self.data, 'rr', -1) + 1 + self.data.rr %= len(connections) + return connections[self.data.rr] class ConnectionPool(object): """