Non-blocking read() in httplib?

Marcin Ciura ciuraNOSPAM at zeus.polsl.gliwice.pl
Mon Jul 12 06:48:28 EDT 2004


I have the following problem with HTTPResponse:

import httplib #, select
...
     connection = httplib.HTTPConnection(host)
     connection.connect()
     connection.request('GET', url)
     response = connection.getresponse()
     # print response.status, response.reason gives '200 OK'
     # ready = select.select([response],[],[], 5.0) # no fileno() method
     # signal.alarm(5) # not on Windows
     # ...
     data=response.read() # this sometimes blocks
     connection.close()

Sometimes the read() call blocks forever for no obvious reason 
(response.status is OK); it even cannot be interrupted from the keyboard 
(on Windows).

I would like to defend against this by throwing an exception when the 
read() lasts too long. But I cannot use select.select(), because 
HTTPResponse has no fileno() method. Neither can I use signal.alarm(), 
as it is for Unixes only.

Is there any other way to break read() or make it non-blocking?

Regards,
   Marcin




More information about the Python-list mailing list