non-blocking sockets and generators

Alan Kennedy alanmk at hotmail.com
Sat May 24 07:53:13 EDT 2003


Gary Stephenson wrote:

> What exception class (if any) should be used to catch the non-blocking
> socket's exception?

I do believe that is "socket.error", i.e. the "error" defined in the
"socket" module. So your try/except should look like this, if you did
"import socket" instead of "from socket import *"

def socketAccept( self, s ) :
    while True :
        try :
            ( sock, addr ) = s.accept()
        except socket.error, serr:
            errno, errstr = serr
            print "Socket error %d: %s" % (errno, errstr)
            yield None
            continue
        self.addThread( self.createThread( sock, addr ) )

HTH,

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list