How to catch socket timeout?

Mickel Grönroos mickel at csc.fi
Wed Sep 24 09:11:27 EDT 2003


On Wed, 24 Sep 2003, Michael Hudson wrote:

> Paul <paul at oz.net> writes:
>
> > What's the best way to do this under Python 2.1?
> > I believe socket.timeout was a 2.3 feature.
> > Wrap it in threads?
>
> There's Tim O'Malley's timeoutsocket.py (google for it), which was the
> inspiration for the feature in 2.3 (though I don't think any code from
> there actually survived).

I can't get the timeoutsocket module to work on my Redhat Linux! (The
timeout works fine on Windows 2000.) I'm running Python 2.2.2.

Here's the test code:

import timeoutsocket
timeoutsocket.setDefaultSocketTimeout(1)
s = timeoutsocket.socket(timeoutsocket.AF_INET, timeoutsocket.SOCK_STREAM)
s.connect(("www.google.com", 80))
s.close()

Any ideas?

/Mickel G.





More information about the Python-list mailing list