socket , httplib and urllib2 (if you urllib2 interested, I can describe this experience).CLOSE_WAIT state hanging on the system. The reason for this is that the sockets are already closed from the server, but still in memory. Ie, roughly speaking, the close method was not called on the socket, and the object itself is still somewhere in memory.urllib2 , httplib and socket , I received the following information about the mechanism of their work:urllib2.OpenDirector.open .urllib2.HTTPHandler.open method, which in turn calls urllib2.AbstractHTTPHandler.do_opendo_open , an h object is created of type httplib.HTTPConnection to directly perform the communication task. An important point - this object disappears when exiting do_open !h spawns and opens a socket, storing it in its self.sock attribute.h sends the request to the server.do_open requests the server's response from h and gets an object of type r httplib.HTTPResponse .h.sock creates the file object self.fp using the method h.sock.makefile , which will be used by the application for reading data. Again, an important point is that the socket object passed to the constructor is not saved anywhere.do_open wraps the resulting HTTPResponse into a service object and returns it to the application.HTTPResponse .tf.fp._sock.fp._sock.close ()
tf is the link obtained from urllib2.open. Such are the cakes :) This is the way back in 2.5; in 2.4 there are still a couple of bugs worse. I will be glad to any tips on how to correctly defeat this behavior.Source: https://habr.com/ru/post/28887/
All Articles