Skip to content

Commit ed5a1cc

Browse files
HusainZafarhonzakral
authored andcommitted
This commit modifies the elasticsearch/connection_pool.py file to solve the list index out of range error. (elastic#539)
Fixes elastic#371
1 parent 66cc0a8 commit ed5a1cc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

elasticsearch/connection_pool.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
import random
33
import logging
4+
import threading
45

56
try:
67
from Queue import PriorityQueue, Empty
@@ -58,12 +59,12 @@ class RoundRobinSelector(ConnectionSelector):
5859
"""
5960
def __init__(self, opts):
6061
super(RoundRobinSelector, self).__init__(opts)
61-
self.rr = -1
62+
self.data = threading.local()
6263

6364
def select(self, connections):
64-
self.rr += 1
65-
self.rr %= len(connections)
66-
return connections[self.rr]
65+
self.data.rr = getattr(self.data, 'rr', -1) + 1
66+
self.data.rr %= len(connections)
67+
return connections[self.data.rr]
6768

6869
class ConnectionPool(object):
6970
"""

0 commit comments

Comments
 (0)