Giampaolo Rodola' <g.rod...@gmail.com> added the comment: Here's a rewriting attempt (not tested). Now that I look at it I must say it's quite ugly, so I don't think we should follow this road. An alternative I see is to return None in case of errors occurring on accept() and make this very clear in doc. Other than accept(), doc should explicitly show how to use handle_accept() in general, which would end up looking like this:
class SomeServer(asyncore.dispatcher): ... def handle_accept(): conn = self.accept() if conn is None: return else: sock, addr = conn ... ... A completely different approach could be to provide a new "TCPServer" class which deprecates direct accept() method usage. Something like this: class TCPServer(asyncore.dispatcher): def __init__(self, ip, port, handler, interface='', map=None): asyncore.dispatcher.__init__(self, map=map) self.create_socket(family=socket.AF_INET, type=socket.SOCK_STREAM) self.bind((ip, port)) self.listen(5) self.handler = handler def handle_accept(self): try: sock, addr = self.accept() except TypeError: return except socket.error, err: if err[0] != errno.ECONNABORTED: raise return else: if addr == None: return handler = self.handler(conn, self._map) def writable(self): return 0 ...but for some reason I don't like it either. Point is asyncore API design is fundamentally wrong and there's nothing we can do about it unless we break backward compatibility or a brand new "asyncore2" module is written. ---------- keywords: +patch nosy: +pitrou Added file: http://bugs.python.org/file19001/accept.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6706> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com