Catch closed RP, fixes #334.
This commit is contained in:
parent
0c46d9eead
commit
2637254bcf
@ -2,6 +2,7 @@ from hashlib import sha1
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
from sqlalchemy.exc import ResourceClosedError
|
||||||
|
|
||||||
QUERY_STEP = 1000
|
QUERY_STEP = 1000
|
||||||
row_type = OrderedDict
|
row_type = OrderedDict
|
||||||
@ -19,15 +20,18 @@ def convert_row(row_type, row):
|
|||||||
|
|
||||||
def iter_result_proxy(rp, step=None):
|
def iter_result_proxy(rp, step=None):
|
||||||
"""Iterate over the ResultProxy."""
|
"""Iterate over the ResultProxy."""
|
||||||
while True:
|
try:
|
||||||
if step is None:
|
while True:
|
||||||
chunk = rp.fetchall()
|
if step is None:
|
||||||
else:
|
chunk = rp.fetchall()
|
||||||
chunk = rp.fetchmany(size=step)
|
else:
|
||||||
if not chunk:
|
chunk = rp.fetchmany(size=step)
|
||||||
break
|
if not chunk:
|
||||||
for row in chunk:
|
break
|
||||||
yield row
|
for row in chunk:
|
||||||
|
yield row
|
||||||
|
except ResourceClosedError:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class ResultIter(object):
|
class ResultIter(object):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user