Wednesday, October 26, 2011

Python: How to “kill” an hanging HTTPConnection object

This may typically happen when you have an httplib.HTTPConnection object which is performing getresponse() in another thread and is, well, waiting...

Suppose you have the urgent need to terminate it. You don’t have a terminate() method. What you need is the sock attribute (undocumented), which gives you access to the corresponding socket.Socket object. On this object you can call shutdown().

So you go:


as in this (production) example:

No comments:

Post a Comment