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