Alarms in threads - how to get/mimic?

Luca de Alfaro dealfaro at eecs.berkeley.edu
Sun Dec 17 02:56:26 CET 2000


Dear Lloyd, 

[in CC to newsgroup, in case this is of general interest]
thank you very much for your reply!  
I got the module, and read its documentation. 
The only point that is not clear to me is the following: 
In the documentation, Timothy states that one can just use
timeoutsocket as a replacement for socket, and all other modules, such
as httplib, will then have timeout capability. 

What is not clear to me is the following.  When there is a timeout,
the exception Timeout is not caught by httplib.  Hence, if the thread
that called httplib just continues its job giving up on the
connection, httplib will not have a chance to do any clean-up, such as
for example releasing/closing the socket. 

Hence, it seems to me that in order to abort a web page load cleanly
upon timeout, I also have to modify the httplib module to handle the
exception Timeout, and do clean-up work if that happens. 

Is my understanding correct? 

Luca

On 16 Dec 2000, Lloyd Zusman wrote:

> Perhaps Timothy O'Malley's `timeoutsocket' class will help you.  It
> allows you to set timeouts for selected socket operations, such as the
> httplib connect calls you're referring to.  You can get it here ...
> 
>   http://www.timo-tasi.org/python/
[...]
> 
> Using this module, you can cause each httplib connection statement
> which times out to throw an exception, and each thread can then
> intelligently respond to its own exception.
> 
> I've been using this module for a similar purpose, and I'm quite
> happy with it.





More information about the Python-list mailing list