Abort an HTTP request before the request timed out

Gelonida N gelonida at gmail.com
Mon Feb 27 03:22:26 CET 2012


I'm working in a small application, which tries to access data on a web

Normally the request has a timeout of for example 60 seconds

conn = httplib.HTTPConnection(server_name, server_port, timeout=60)
while True:
    conn.request("GET", "/my_url.php")
        resp = conn.getresponse()
    except HaveToLookUpNameOfTimeOutException as exc:
        print "timed out"

Sometimes I would like to abort the request from another thread and
force an immediate retry.

How would I do this best?
The other thread would be either a UI button or some other code knowing,
when it is not good to wait the ull minute.

Normally the timeout of 1 mintues is what I need though.

Thanks for any suggestion.

The solution should work on Windows and Linux

More information about the Python-list mailing list