我正在使用这个库:ESCPOS Printer for Python using the Ethernet class 为了与打印机通信:CLASS ESCPOS ETHERNET
我正在尝试使用简单的线程执行大量调用,如上所示:
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()
但它经常失败,给我错误:Err 60 Connection timed out,我的意思是,为什么使用线程并发调用打印机我遇到了这个问题?
谁能帮我解决这个问题?
谢谢