Close csv files after dumping

PyPy doesn't collect garbage as quickly as CPython, so it was possible
for the process to exit before all the files had been flushed.
This commit is contained in:
Andrew Ekstedt 2021-03-19 22:38:32 -07:00
parent 340ba4750f
commit f865943a3d

View file

@ -441,10 +441,12 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
# CSV module only works with bytes on 2 and only works with text on 3! # CSV module only works with bytes on 2 and only works with text on 3!
if six.PY3: if six.PY3:
writer = csv.writer(open(filename, 'w', newline='', encoding="utf8"), lineterminator='\n') csvfile = open(filename, 'w', newline='', encoding="utf8")
writer = csv.writer(csvfile, lineterminator='\n')
columns = [col.name for col in table.columns] columns = [col.name for col in table.columns]
else: else:
writer = csv.writer(open(filename, 'wb'), lineterminator='\n') csvfile = open(filename, 'wb')
writer = csv.writer(csvfile, lineterminator='\n')
columns = [col.name.encode('utf8') for col in table.columns] columns = [col.name.encode('utf8') for col in table.columns]
# For name tables, always dump rows for official languages, as well as # For name tables, always dump rows for official languages, as well as
@ -491,4 +493,5 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
writer.writerow(csvs) writer.writerow(csvs)
csvfile.close()
print_done() print_done()