This commit is contained in:
zman 2025-04-07 17:22:26 -04:00
parent a576cea8e8
commit c53baccb38

10
app.py
View File

@ -33,6 +33,9 @@ printer_model = "QL-1100"
backend = 'pyusb' backend = 'pyusb'
printer = 'usb://0x04f9:0x20a7' printer = 'usb://0x04f9:0x20a7'
# Create a lock to manage printer access
printer_lock = threading.Lock()
# Convert PDF to image # Convert PDF to image
def convert_pdf_to_image(pdf_path): def convert_pdf_to_image(pdf_path):
"""Converts a PDF to a PIL Image""" """Converts a PDF to a PIL Image"""
@ -76,7 +79,10 @@ def print_address_label(pdf_path):
cut=True cut=True
) )
app.logger.info("Waiting to acquire printer lock...")
with printer_lock: # Ensure only one thread sends a job at a time
app.logger.info("Sending to printer...") app.logger.info("Sending to printer...")
try:
send( send(
instructions=instructions, instructions=instructions,
printer_identifier=printer, printer_identifier=printer,
@ -84,10 +90,12 @@ def print_address_label(pdf_path):
blocking=True blocking=True
) )
app.logger.info("Print job sent successfully") app.logger.info("Print job sent successfully")
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)}")
except Exception as e:
app.logger.error(f"Error during label printing: {str(e)}")
# Worker thread that processes files from the queue # Worker thread that processes files from the queue
def process_queue(): def process_queue():
while True: while True: