From 2490be849045d361ba5c9913a42949027e361f6c Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 29 Mar 2020 21:53:45 -0700 Subject: [PATCH] Fix debug.log not being deleted on Windows (probably) Fixes #515 --- src/ocrmypdf/_sync.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ocrmypdf/_sync.py b/src/ocrmypdf/_sync.py index c397b3f4..07c355ab 100644 --- a/src/ocrmypdf/_sync.py +++ b/src/ocrmypdf/_sync.py @@ -361,10 +361,11 @@ def run_pipeline(options, api=False): options.jobs = available_cpu_count() work_folder = mkdtemp(prefix="com.github.ocrmypdf.") + debug_log_handler = None if (options.keep_temporary_files or options.verbose >= 1) and not os.environ.get( 'PYTEST_CURRENT_TEST', '' ): - configure_debug_logging(Path(work_folder) / "debug.log") + debug_log_handler = configure_debug_logging(Path(work_folder) / "debug.log") try: check_requested_output_file(options) @@ -432,6 +433,12 @@ def run_pipeline(options, api=False): log.exception("An exception occurred while executing the pipeline") return ExitCode.other_error finally: + if debug_log_handler: + try: + debug_log_handler.close() + log.removeHandler(debug_log_handler) + except EnvironmentError as e: + print(e, file=sys.stderr) cleanup_working_files(work_folder, options) return ExitCode.ok