python - Close lingering connection -


I am using Python-requests for client tools. It repeatedly requests the server for intervals. However, if the server is disconnected, the client fails with the socket error on its next request. It appears that the client opens the connection from his side, instead of connecting again. These connection hours can vary, so it is not possible that the server will not disconnect it.

What is a way to keep it alive and forced to stop it? Is there something like this:

  with r: doStuff (r) # R is cleared as request.get (url), socket is off   

Can I be forced to clean the connection after I do?

As written, it does not work, because the request. Response is not a __

How about this?

I did not test it, based only on the API doctor:

  s = request Session () r = s.get (url) doStuff (r) s.close ()   

Or, to ensure that it is always said near, even if there are exceptions , Here it has been attempted that at end / end by using Android:

  s = requests.Session (try): r = s.get (url) doStuff (R) end: S.close ()    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -