0

I have a python program where I use a server socket to send data. There is a class which has some Threading methods. Each method checks a queue and if the queue is not empty, it sends the data over the sever socket. Queues are being filled with what clients send to server(server is listening for input requests). Sending is accomplished with a method call:

def send(self, data):
    self.sqn += 1
    try:
        self.clisock.send(data)
    except Exception, e:
        print 'Send packet failed with error: ' + e.message

When the program starts, sending rate is around 500, but after a while it decreases instantly to 30 with this exception:

Send packet failed with error: <class 'socket.error'>>>[Errno 32] Broken pipe 

I don't know what causes the rate to increase! Any idea?

Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131
  • You can try to catch this exception and close the socket accordingly which could possibly increase the sending rate. – Stephen Lin May 10 '15 at 14:31

1 Answers1

1

That error is from your send function trying to write to a socket closed on the other side. If that is intended then catch the exception using

import errno, socket
try:
    self.clisock.send(data)
except socket.error, err:
    if err[0] == errno.EPIPE:
        # do something
    else:
        pass # do something else

If this isn't intended behavior on the part of the client then you'll have to update your post with the corresponding client code.

chemdt
  • 138
  • 8