catch non-blocking socket exceptions

Peter Hansen peter at
Thu Jun 26 17:17:02 CEST 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

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.


More information about the Python-list mailing list