Fix #219: catch BrokenPipeError

This commit is contained in:
Arun Prakash Jana 2017-10-11 18:09:30 +05:30
parent fd49d30a3e
commit 98fd16f075
No known key found for this signature in database
GPG Key ID: A75979F35C080412

View File

@ -3231,6 +3231,7 @@ def print_rec_with_filter(records, field_filter=0):
Integer indicating which fields to print. Integer indicating which fields to print.
""" """
try:
if field_filter == 0: if field_filter == 0:
for row in records: for row in records:
print_single_rec(row) print_single_rec(row)
@ -3258,6 +3259,9 @@ def print_rec_with_filter(records, field_filter=0):
elif field_filter == 40: elif field_filter == 40:
for row in records: for row in records:
print('%s\t%s\t%s' % (row[1], row[2], row[3][1:-1])) print('%s\t%s\t%s' % (row[1], row[2], row[3][1:-1]))
except BrokenPipeError:
sys.stdout = os.fdopen(1)
sys.exit(1)
def print_single_rec(row, idx=0): # NOQA def print_single_rec(row, idx=0): # NOQA
"""Print a single DB record. """Print a single DB record.
@ -3293,8 +3297,11 @@ def print_single_rec(row, idx=0): # NOQA
if row[3] != DELIM: if row[3] != DELIM:
str_list.append(TAG_str % (row[3][1:-1])) str_list.append(TAG_str % (row[3][1:-1]))
try:
print(''.join(str_list)) print(''.join(str_list))
except BrokenPipeError:
sys.stdout = os.fdopen(1)
sys.exit(1)
def format_json(resultset, single_record=False, field_filter=0): def format_json(resultset, single_record=False, field_filter=0):
"""Return results in json format. """Return results in json format.