Abort an HTTP request before the request timed out

Gelonida N gelonida at gmail.com
Sun Feb 26 21:22:26 EST 2012


Hi,

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

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")
    try:
        resp = conn.getresponse()
    except HaveToLookUpNameOfTimeOutException as exc:
        print "timed out"
        continue
    parse_response(resp)

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