catch non-blocking socket exceptions
Peter Hansen
peter at engcorp.com
Thu Jun 26 11:17:02 EDT 2003
Axel Bock wrote:
>
> I try to connect to several hosts at once to verify whether a certain
> service is running. Now it's quite stupid to connect to one after another,
> cause if I do this I'll wait forever if some hosts don't respond (at least
> until TCP timeout).
>
> But if I connect to several hosts in parallel and use polling objects I'm
> stuck - I don't know how to handle exceptions: are they raised as normal?
> If yes, how do I get the correspondig socket object - or file number?
> If no, how do I know if a socket timed out, or refused connection, or
> something similar?
Check out these pages for some background (especially page four on non-blocking
sockets):
http://www.mcmillan-inc.com/sock1.html
But consider just using Twisted and letting all this stuff be handled
for you... no sense reinventing the wheel in an area that is notoriously
difficult to do right.
-Peter
More information about the Python-list
mailing list