question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

list index out of range on multithreaded environment

See original GitHub issue

Hi, first of all, thank you very much for elasticsearch, you are doing a very nice job. This is my first contribution to the community so please be nice with me.

I’m working on a multithreaded enviroment (using multiprocessing.pool.ThreadPool), and sometimes the following error appear:

File "/opt/clustering/wrappers/DAOElasticSearch/DAOElasticSearch.py", line 77, in indexDocument
    self.index(index = self.indexName, doc_type = self.docType, body = document, **kwargs)
File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 261, in index
    _make_path(index, doc_type, id), params=params, body=body)
File "/usr/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 326, in perform_request
    connection = self.get_connection()
File "/usr/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 182, in get_connection
    return self.connection_pool.get_connection()
File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection_pool.py", line 225, in get_connection
    return self.selector.select(self.connections)
File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection_pool.py", line 66, in select
    return connections[self.rr]

Is this a problem with my code or is this a bug of elasticsearch client? Looking over /usr/local/lib/python2.7/site-packages/elasticsearch/connection_pool.py, I think that this can be solved using some kind of Lock() or Semaphore() protecting connections variable.

Thanks again, Victor.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
marcinncommented, Dec 21, 2016

Maybe storing rr in threading.local() context in RoundRobinSelector will resolve the issue?

0reactions
honzakralcommented, Feb 19, 2017

Fixed via #539, thanks, @HusainZafar!

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexError: list index out of range error while multithreading
Your problem has nothing to do with multithreading, it's just because results is an empty list. As the comment said, check it's lenght ......
Read more >
List Index Out of Range – Python Error [Solved] - freeCodeCamp
This error generally occurs when we try to access an item in a list by using an index that doesn't exist within the...
Read more >
DispatchQueue, index out of range, tableView
I can do this multiple times with no crash or index out or range. Only when I put the disptachQueue, it works one...
Read more >
List Index out of Range Python for Loop - TutorialAndExample
The List is generally used in Python to store multiple items or elements inside one single variable. The List is ordered in nature,...
Read more >
IndexOutOfRangeException Class (System) - Microsoft Learn
The exception that is thrown when an attempt is made to access an element of an array or collection with an index that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found