What part of python.socket could conceivably freeze my script for ever even though timeout is set?
The oauth library (Linked from the Justin.tv Python library page) locks up my Python processes indefinitely at random times. This happens randomly, but OFTEN on one of my servers. I'm positive this is not due to anything in my code, so I'm pasting the part of the stack dump related to the Justin.tv python library and oauth:
File "/home/honstreams/honstreams/website/JtvClient.py", line 51, in get return self._send_request(request, token) File "/home/honstreams/honstreams/website/JtvClient.py", line 90, in _send_request return conn.getresponse() File "/usr/lib/python2.6/httplib.py", line 986, in getresponse response.begin() File "/usr/l开发者_如何转开发ib/python2.6/httplib.py", line 391, in begin version, status, reason = self._read_status() File "/usr/lib/python2.6/httplib.py", line 349, in _read_status line = self.fp.readline() File "/usr/lib/python2.6/socket.py", line 397, in readline data = recv(1) KeyboardInterrupt
The bottom line is where it's stuck before the KeyboardInterrupt
. I will stay on that line for ever, or at least for the few days I let it run.
I'm interested in any way socket.py
can lock up even though timeout is set (Some times it does time out) and any way it can be prevented.
Here is a bit more information
root@foo:~# python --version Python 2.6.5 root@foo:~# uname -a Linux foo.bar.no 2.6.32-31-generic-pae #61-Ubuntu SMP Fri Apr 8 20:00:13 UTC 2011 i686 GNU/Linux
These lines from the Justin.tv Python Client Library are relevant:
def _send_request(self, request, token=None):
request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, token)
conn = self._get_conn() # connection was requested here
if request.http_method == 'POST':
conn.request('POST', request.http_url, body=request.to_postdata())
else:
conn.request('GET', request.http_url, headers=request.to_header())
return conn.getresponse() # Error occurs here
def _get_conn(self):
return httplib.HTTPConnection("%s:%d" % (self.host, self.port)) # no timeout!
Notice that the httplib.HTTPConnection
is not passed any timeout. Change that code to take a timeout and make sure to define what happens when a timeout occurs.
精彩评论