Fix memory leak, fixes #226.
This commit is contained in:
parent
71b9421d60
commit
fc3af9e1f1
@ -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)
|
||||
|
||||
|
||||
@ -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__
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user