Skip to content

Commit 3a9ce0f

Browse files
committed
fitdump: Always try to close output file
1 parent 5a02aef commit 3a9ce0f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎scripts/fitdump‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,17 @@ def main(args=None):
107107
as_dict=options.as_dict
108108
)
109109

110-
if options.type == "json":
111-
json.dump(records, fp=options.output, cls=RecordJSONEncoder)
112-
elif options.type == "readable":
113-
options.output.writelines(format_message(n, record, options)
114-
for n, record in enumerate(records, 1))
115-
110+
try:
111+
if options.type == "json":
112+
json.dump(records, fp=options.output, cls=RecordJSONEncoder)
113+
elif options.type == "readable":
114+
options.output.writelines(format_message(n, record, options)
115+
for n, record in enumerate(records, 1))
116+
finally:
117+
try:
118+
options.output.close()
119+
except IOError:
120+
pass
116121

117122
if __name__ == '__main__':
118123
try:

0 commit comments

Comments
 (0)