petervizi / python-eeml

A python package for generating eeml documents.
http://petervizi.github.com/python-eeml
GNU General Public License v3.0
43 stars 11 forks source link

http PUT blocks if no response from pachube #6

Closed nferreyra closed 12 years ago

nferreyra commented 12 years ago

I Peter. I found out some blocking situations due to missing 200 OK from Pachube. In that circumstances the put method will block indefinitely. My suggestion is to setup a socket timeout just after creating the request. Something like:

    conn.request('PUT', self._url, self._eeml.toeeml().toxml(), {'X-PachubeA...
    conn.sock.settimeout(5.0)                                               
    resp = conn.getresponse()                                               
    if resp.status != 200:                                                  
        raise Exception(resp.reason)                                        
    resp.read()                                                             
    conn.close()                          

This make the connection to unblock after a 5s socket inactivity. You can also make it a property of the constructor. Please continue the good work.

Thank you

petervizi commented 12 years ago

Thanks for your suggestion, hope you like the implementation.

nferreyra commented 12 years ago

Hi Peter. I believe that will not fix the problem. The timeout you are setting is for connection timeouts and not for inactivity on the socket like absence of HTTP responses.

To validate it you can hijack your host table making api.pachube.com to 127.0.0.1 and start nc on port 80: nc -l 80

After that you just need to put something to pachube to see it blocking.

Thanks

petervizi commented 12 years ago

I modified the code as suggested, let me know of any issues.