This commit is contained in:
zman 2025-04-07 17:54:54 -04:00
parent d06716ac92
commit 00d737714b

27
app.py
View File

@ -11,7 +11,6 @@ import mimetypes
import logging import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
import time import time
import fcntl # For file locking
app = Flask(__name__) app = Flask(__name__)
@ -85,23 +84,14 @@ def print_address_label(pdf_path):
cut=True cut=True
) )
app.logger.info("Attempting to acquire printer lock...") app.logger.info("Sending to printer...")
send(
# Open the printer device and lock it to prevent concurrent access instructions=instructions,
with open(printer, 'wb') as printer_device: printer_identifier=printer,
fcntl.flock(printer_device, fcntl.LOCK_EX) # Exclusive lock on printer device backend_identifier=backend,
try: blocking=True
app.logger.info("Sending to printer...") )
send( app.logger.info("Print job sent successfully")
instructions=instructions,
printer_identifier=printer,
backend_identifier=backend,
blocking=True
)
app.logger.info("Print job sent successfully")
finally:
# Ensure the lock is released after the print job is finished
fcntl.flock(printer_device, fcntl.LOCK_UN)
except Exception as e: except Exception as e:
app.logger.error(f"Error during printing: {str(e)}") app.logger.error(f"Error during printing: {str(e)}")
@ -116,7 +106,6 @@ def process_queue():
# Process the file (convert and print) # Process the file (convert and print)
app.logger.info(f"Processing file: {file_path}") app.logger.info(f"Processing file: {file_path}")
print_address_label(file_path) print_address_label(file_path)
time.sleep(10)
# Signal that the task is done # Signal that the task is done
file_queue.task_done() file_queue.task_done()