From a60cfae01cb62017f7ef7e8000c3a9358d1df82c Mon Sep 17 00:00:00 2001 From: zman Date: Mon, 7 Apr 2025 17:50:44 -0400 Subject: [PATCH] ASDFASDFAS --- app.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 26009d1..07ccaa3 100644 --- a/app.py +++ b/app.py @@ -48,7 +48,7 @@ def convert_pdf_to_image(pdf_path): return None # Function to print address labels -def print_address_label(pdf_path): +def print_address_label(pdf_path, print_complete_event): try: # Convert PDF to image image = convert_pdf_to_image(pdf_path) @@ -95,6 +95,10 @@ def print_address_label(pdf_path): except Exception as e: app.logger.error(f"Error during printing: {str(e)}") + + finally: + # Signal that the current print job is done + print_complete_event.set() # Worker thread that processes files from the queue def process_queue(): @@ -103,10 +107,17 @@ def process_queue(): file_path = file_queue.get() if file_path is None: # Shutdown signal break + + # Create an event to signal print job completion + print_complete_event = threading.Event() + # Process the file (convert and print) app.logger.info(f"Processing file: {file_path}") - print_address_label(file_path) - time.sleep(10) + print_address_label(file_path, print_complete_event) + + # Wait until the current print job is completed before processing the next one + print_complete_event.wait() + # Signal that the task is done file_queue.task_done()