Skip to content

Commit

Permalink
Readqueue leak fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vilim committed Apr 9, 2019
1 parent 54b89a6 commit 1202da7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
@@ -0,0 +1,4 @@
# 1.2.0

## Fixes
- subclasses of arrayqueue clear the readqueue correctly now.
19 changes: 12 additions & 7 deletions arrayqueues/shared_arrays.py
Expand Up @@ -54,12 +54,13 @@ def __init__(self, max_mbytes=10):
def check_full(self):
while True:
try:
self.last_item = self.read_queue.get(timeout=0.000001)
self.last_item = self.read_queue.get(timeout=0.00001)
except Empty:
break
if self.view.i_item == self.last_item:
raise Full("Queue of length {} full when trying to insert {}, last item read was {}".format(self.view.n_items,
self.view.i_item, self.last_item))
raise Full("Queue of length {} full when trying to insert {},"
" last item read was {}".format(self.view.n_items,
self.view.i_item, self.last_item))

def put(self, element):
if self.view is None or not self.view.fits(element):
Expand Down Expand Up @@ -87,16 +88,14 @@ def clear(self):
:return: nothing
"""
self.view = None

while True:
try:
self.queue.get(timeout=0.0)
it = self.queue.get_nowait()
except Empty:
break

while True:
try:
self.read_queue.get(timeout=0.0)
it = self.read_queue.get_nowait()
except Empty:
break

Expand All @@ -115,6 +114,9 @@ def put(self, element, timestamp=None):
if self.view is None or not self.view.fits(element):
self.view = ArrayView(self.array.get_obj(), self.maxbytes,
element.dtype, element.shape)
else:
self.check_full()

qitem = self.view.push(element)
if timestamp is None:
timestamp = datetime.now()
Expand Down Expand Up @@ -143,6 +145,9 @@ def put(self, element, timestamp=None):
if self.view is None or not self.view.fits(element):
self.view = ArrayView(self.array.get_obj(), self.maxbytes,
element.dtype, element.shape)
else:
self.check_full()

qitem = self.view.push(element)
if timestamp is None:
timestamp = datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@
from setuptools import find_packages

setup(name='arrayqueues',
version='1.1.0b0',
version='1.2.0b0',
author='Vilim Stih @portugueslab',
author_email='vilim@neuro.mpg.de',
license='MIT',
Expand Down

0 comments on commit 1202da7

Please sign in to comment.