non-blocking sockets and generators

Alex Martelli aleaxit at yahoo.com
Sat May 24 09:55:57 EDT 2003


Gary Stephenson wrote:

> Whoops.  I figured out the answer to my first question anyway.
> 
>>     def socketAccept( self, s ) :
>>         while True :
>>             try :
>>                 ( sock, addr ) = s.accept()
>>             except :
>>                 yield None
>                    continue     #  <<  missing from previous version
>>             self.addThread( self.createThread( sock, addr ) )
> 
> So the exception was thrown err the assignment completed.  In the absence
> of the (now added) continue statement execution of the last line indeed
> proceeded without sock having been assigned to.
> 
> However, my _second_ question re the appropriate error class to use
> survives intact.

I think you may be looking for:

  except socket.error:

(which needs an 'import socket' somewhere earlier in your source).


Alex





More information about the Python-list mailing list