From f865943a3df55d174b55a31a9ceda6f833c77347 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Fri, 19 Mar 2021 22:38:32 -0700 Subject: [PATCH] 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. --- pokedex/db/load.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pokedex/db/load.py b/pokedex/db/load.py index b787672..631fc9b 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -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! 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] 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] # 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) + csvfile.close() print_done()