Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Too Many Files Open" Error - Files Not Being Closed? #108

Closed
brc591 opened this issue Nov 6, 2015 · 6 comments
Closed

"Too Many Files Open" Error - Files Not Being Closed? #108

brc591 opened this issue Nov 6, 2015 · 6 comments

Comments

@brc591
Copy link

brc591 commented Nov 6, 2015

I've been using the ANNOY Python API to build and save several index tables in order to load and reuse subsets of these in another script (at most about 400 in a subset at a time). The library is wonderfully fast, but I've been encountering "too many files open" errors after some time. I'm loading each index once, doing stuff with it, then unloading it before the loop continues onwards with the next index table.

Here is a partial code snippet that reproduces the error by reloading the same index table (510 x 64) over and over (run the loop multiple times if the error doesn't show up immediately):

from annoy import AnnoyIndex
index_table = AnnoyIndex( 64,metric='angular' )
for i in xrange(10000):
    index_table.load( index_table_filename )
    print i  # just seeing when it failed
    index_table.unload( index_table_filename )

After some sleuthing into the GitHub source code, I notice that unload() unmaps the file from memory, but doesn't close the file opened using load(). Would it be possible to get file closing functionality incorporated into the Python wrapper somehow please? Or am I missing something vital in using ANNOY?

Thanks for all the hard work on the API!

@erikbern
Copy link
Collaborator

erikbern commented Nov 6, 2015

Yes that seems correct, glancing at the code, the fd file is never closed in the unload function.

Do you want to put together a pull request for this?

@erikbern
Copy link
Collaborator

erikbern commented Nov 6, 2015

would be awesome if you can include that code sample as a unit test

@brc591
Copy link
Author

brc591 commented Nov 6, 2015

I haven't used GitHub before aside from browsing through code and downloading projects, so please bear with me.

What is it that you're asking/wanting me to do?

@erikbern
Copy link
Collaborator

erikbern commented Nov 6, 2015

It should take me a few minutes, so I can do it.. give me 5 min

@erikbern
Copy link
Collaborator

erikbern commented Nov 6, 2015

something is weird with my python installation – i'll take a look later

erikbern pushed a commit that referenced this issue Nov 7, 2015
erikbern pushed a commit that referenced this issue Nov 7, 2015
erikbern pushed a commit that referenced this issue Nov 7, 2015
Fix double save but in #100
@brc591
Copy link
Author

brc591 commented Nov 9, 2015

Sorry for the late reply, but just wanted to say thank you very much for the fix! Just tested it out on my end and it's running without qualms here. So thank you again!

erikbern pushed a commit that referenced this issue Nov 13, 2015
- KISS random number generators
- normalize euclidean distance
- Close file handlers, simpler reinit code
- Fixed kwargs for get_nns_by_item
- Fixed issue leading to nan distances returned

Resolving #108, #109, #100 and some other bugs
erikbern pushed a commit that referenced this issue Jan 31, 2016
erikbern pushed a commit that referenced this issue Jan 31, 2016
- KISS random number generators
- normalize euclidean distance
- Close file handlers, simpler reinit code
- Fixed kwargs for get_nns_by_item
- Fixed issue leading to nan distances returned

Resolving #108, #109, #100 and some other bugs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants