Fix memory leak, fixes #226.

This commit is contained in:
Friedrich Lindenberg 2020-01-11 15:01:22 +01:00
parent 71b9421d60
commit fc3af9e1f1
2 changed files with 8 additions and 2 deletions

View File

@ -254,6 +254,8 @@ class Database(object):
if isinstance(query, str):
query = text(query)
_step = kwargs.pop('_step', QUERY_STEP)
if _step is False or _step == 0:
_step = None
rp = self.executable.execute(query, *args, **kwargs)
return ResultIter(rp, row_type=self.row_type, step=_step)

View File

@ -23,7 +23,7 @@ def iter_result_proxy(rp, step=None):
if step is None:
chunk = rp.fetchall()
else:
chunk = rp.fetchmany(step)
chunk = rp.fetchmany(size=step)
if not chunk:
break
for row in chunk:
@ -41,7 +41,11 @@ class ResultIter(object):
self._iter = iter_result_proxy(result_proxy, step=step)
def __next__(self):
return convert_row(self.row_type, next(self._iter))
try:
return convert_row(self.row_type, next(self._iter))
except StopIteration:
self.close()
raise
next = __next__