non-blocking socket connects?

Gary Stephenson garys at ihug.com.au
Sun May 25 00:03:32 EDT 2003


Hi again,

I'm trying to do a non-blocking socket connect(), but the following code
never completes:

    def _connect( self ) :
        print "connecting to ", self.addr, self.port
        while True :
            try :
                self.sock.connect( (self.addr, self.port) )
            except socket.error :
                #  _always_ occurs
                yield None
                continue
            except :
                #  _never_ occurs
                print "connection error"
            break
        print "connected"

whereas this code works just fine:

    def _connect( self ) :
        self.sock.setblocking( True )
        self.sock.connect( (self.addr, self.port) )
        self.sock.setblocking( False )

Can anybody please enlighten me as to what I'm doing wrong with the first
version?

many tias,

gary






More information about the Python-list mailing list