i'm working with this library: ESCPOS Printer for Python using the Ethernet class in order to communicate with printer: CLASS ESCPOS ETHERNET
I'm trying to execute a lot of calls using simple threads, like above:
from time import sleep
import requests
import threading
import datetime
from escposprinter import *
from escposprinter.escpos import EscposIO, Escpos
NumeroPartenza = 0
NumeroFine = 9
NumeroStampePerStampante = 1
printerPort = 9100
dictionaryStampanti = {'printer1' : '192.168.0.196','printer2' : '192.168.0.197', 'printer3' : '192.168.0.198'}
def printSimple(threadName, stampanteIp):
with EscposIO(printer.Network(stampanteIp, printerPort)) as p:
for iteration in range(NumeroStampePerStampante):
p.set(font='a', codepage='cp1251', size='normal', align='center', bold=True)
p.writelines('')
p.writelines('')
p.writelines('')
p.writelines("{0}: {1}".format( threadName, datetime.datetime.now().strftime("%H:%M:%S.%f")))
p.writelines('')
p.writelines('')
p.writelines('')
#Testa stampante semplice
for Ordine in range(NumeroPartenza, NumeroFine):
stringToPrint = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
threading.Thread(target=printSimple, args=("Thread1: " + stringToPrint, dictionaryStampanti.get('printer1')), ).start()
threading.Thread(target=printSimple, args=("Thread2: " + stringToPrint, dictionaryStampanti.get('printer1')), ).start()
threading.Thread(target=printSimple, args=("Thread3: " + stringToPrint, dictionaryStampanti.get('printer1')), ).start()
But frequently it fails, giving me the error: Err 60 Connection timed out, i mean, why using threads with concurrency calls to the printer i'm encountering this problem?
Can anyone help me to solve this issue?
Thanks