winziprint: delete temp files in finally block
This commit is contained in:
@ -19,6 +19,7 @@ def convert(input_file_names: list[str], output_file_name: str, encoding: str =
|
||||
page_nums = []
|
||||
tmp_file_names = []
|
||||
|
||||
try:
|
||||
for i in range(0, len(input_file_names), BATCH_SIZE):
|
||||
batch = input_file_names[i:i + BATCH_SIZE]
|
||||
documents = []
|
||||
@ -39,9 +40,13 @@ def convert(input_file_names: list[str], output_file_name: str, encoding: str =
|
||||
merger = pypdf.PdfWriter()
|
||||
for pdf in tmp_file_names:
|
||||
merger.append(pdf)
|
||||
os.remove(pdf)
|
||||
merger.write(output_file_name)
|
||||
merger.close()
|
||||
del merger
|
||||
finally:
|
||||
for pdf in tmp_file_names:
|
||||
if os.path.isfile(pdf):
|
||||
os.remove(pdf)
|
||||
|
||||
return page_nums
|
||||
|
||||
@ -59,6 +64,8 @@ def _wrapper_convert(args: list[str], encoding: str = None) -> None:
|
||||
msg = str(e).replace('\n', ' ')
|
||||
print(f'error: {msg}', flush=True)
|
||||
traceback.print_exception(e)
|
||||
finally:
|
||||
gc.collect()
|
||||
|
||||
|
||||
def usage() -> None:
|
||||
|
Reference in New Issue
Block a user