non-blocking sockets and generators

Gary Stephenson garys at ihug.com.au
Sat May 24 19:09:46 EDT 2003


Alan and Alex,

Many .thanks.  Hopefully sometime soon I'll graduate from newbie status and
be able to stop asking really stoopid questions and maybe even ask some
intelligent ones!  <g>    The module / import mechanism seems to be the
aspect I'm having the most trouble with - prolly 'coz my current language
lacks any such mechanism at all.

gary




"Alan Kennedy" <alanmk at hotmail.com> wrote in message
news:3ECF5D29.1C48A8A1 at hotmail.com...
> 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