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

Protect against empty heap. #15

Merged
merged 1 commit into from
Mar 4, 2019
Merged

Protect against empty heap. #15

merged 1 commit into from
Mar 4, 2019

Conversation

rainwoodman
Copy link
Contributor

I do not understand how this can happen, but we are seeing this stack trace:

../testenv/lib/python3.6/site-packages/nbodykit/tests/test_cache.py:19: in test_cache
    cache.cache.shrink()
/home/travis/miniconda/envs/test/lib/python3.6/site-packages/cachey/cache.py:139: in shrink
    self._shrink_one()
/home/travis/miniconda/envs/test/lib/python3.6/site-packages/cachey/cache.py:126: in _shrink_one
    key, score = self.heap.popitem()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <heapdict.heapdict object at 0x7f24b44e46d8>
    def popitem(self):
        """D.popitem() -> (k, v), remove and return the (key, value) pair with lowest\nvalue; but raise KeyError if D is empty."""
>       wrapper = self.heap[0]
E       IndexError: list index out of range
/home/travis/miniconda/envs/test/lib/python3.6/site-packages/heapdict.py:91: IndexError

This should fix the stack trace, but it is not clear to me how it can happen when the heap is empty yet total_bytes is not zero.

I do not understand how this can happen, but we are seeing this stack trace:

```
../testenv/lib/python3.6/site-packages/nbodykit/tests/test_cache.py:19: in test_cache
    cache.cache.shrink()
/home/travis/miniconda/envs/test/lib/python3.6/site-packages/cachey/cache.py:139: in shrink
    self._shrink_one()
/home/travis/miniconda/envs/test/lib/python3.6/site-packages/cachey/cache.py:126: in _shrink_one
    key, score = self.heap.popitem()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <heapdict.heapdict object at 0x7f24b44e46d8>
    def popitem(self):
        """D.popitem() -> (k, v), remove and return the (key, value) pair with lowest\nvalue; but raise KeyError if D is empty."""
>       wrapper = self.heap[0]
E       IndexError: list index out of range
/home/travis/miniconda/envs/test/lib/python3.6/site-packages/heapdict.py:91: IndexError
```

This should fix the stack trace, but it is not clear to me how it can happen when the heap is empty yet total_bytes is not zero.
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

Successfully merging this pull request may close these issues.

2 participants