python - asyncore server: Request resulting in "socket.error'>:[Errno 32] Broken pipe)" -
i'm writing asyncore server fetches info module in same process , writes client. info dictionary each key have queue of messages. i'm required dump length of each queue. code runs fine on test machine install on production server start getting next error message : "socket.error'>:[errno 32] broken pipe)".
this server:
class request_handler (asyncore.dispatcher): def __init__(self, conn_sock, client_address, dict): self.client_address = client_address self.buffer = "" self.dict = dict asyncore.dispatcher.__init__(self, conn_sock) def readable(self): homecoming true def writable(self): homecoming false def handle_read(self): info = self.recv(size) mtats = "msgq-stats" if data: buffer = info if buffer.lower() == mstats.lower(): msgout = "-- message queue stats --\n" key, value in dict.items(): mq = 0 if dict[key].message_queue: mq = len(dict[key].message_queue) msgout += key + ":" + str(mq) + "\n" self.send(msgout) else: self.send("invalid input\n") else: self.send("invalid input\n") def handle_write(self): print ("--handling read--\n") def handle_close(self): pass # --------------------------------------------------------------------- class monitor_server (asyncore.dispatcher): def __init__ (self, ip, port, destination): sys.path.append('/path/') import dict self.ip = ip self.port = port self.dict = dict asyncore.dispatcher.__init__ (self) self.create_socket (socket.af_inet, socket.sock_stream) self.set_reuse_addr() self.bind ((ip, port)) self.listen (5) def writable (self): homecoming 0 def handle_read (self): pass def readable (self): homecoming self.accepting def handle_connect (self): pass def handle_accept (self): (conn_sock, client_address) = self.accept() request_handler (conn_sock, client_address, self.destination)
and client code:
class client(asyncore.dispatcher_with_send): def __init__(self, host, port, message): asyncore.dispatcher.__init__(self) self.create_socket(socket.af_inet, socket.sock_stream) self.connect((host, port)) print "message beingness sent " print message self.out_buffer = message def handle_close(self): self.close() def handle_read(self): print self.recv(1024) self.close() c = client('', 6000, 'msgq-stats') asyncore.loop()
thanks in advance.
that's error case have handle. connections close. it's normal different socket errors encountered during development compared in production, since there many different possible errors , exclusively depend on execution environment , programme on other side of connection doing , on routers between client , server decide do.
so, literal reply question need handle , many other socket errors in application code. that's part of job when utilize asyncore. add together necessary exception handling , mark connection closed when happens.
a improve reply there higher level tools create network programming easier, , should consider using those. big thing in area twisted.
python asyncore
No comments:
Post a Comment