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

26
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,17 +79,22 @@ def print_address_label(pdf_path):
cut=True cut=True
) )
app.logger.info("Sending to printer...") app.logger.info("Waiting to acquire printer lock...")
send( with printer_lock: # Ensure only one thread sends a job at a time
instructions=instructions, app.logger.info("Sending to printer...")
printer_identifier=printer, try:
backend_identifier=backend, send(
blocking=True instructions=instructions,
) printer_identifier=printer,
app.logger.info("Print job sent successfully") 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)}")
except Exception as e: except Exception as e:
app.logger.error(f"Error during printing: {str(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():