0

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

Symon
  • 673
  • 6
  • 25
  • All the threads are trying to print to the same printer, is that intentional or a bug in your program? I mean why having the dictionary with different IPs if you choose the very same one for each thread? – BlackJack May 19 '16 at 14:41
  • Yeah that's right, this was a test of multiple concurrency socket opened on same printer...any suggest? – Symon May 23 '16 at 07:01
  • Yes: Don't do that. :-) – BlackJack May 23 '16 at 16:40

0 Answers0