python - How to close connections in Requests (scalability) -


what equivalent of this, using requests library?

with contextlib.closing(urllib2.urlopen(request)) response:     return response.read().decode('utf-8') 

requests seems more modern solution 2.7 urllib2.

what correct way close connections, running function 800 times or so, won't leave connections open , cause performance issues? should create session , use close() on it?

is this?

s = requests.session() s.get('http://httpbin.org/get') s.close() 

there should no connections open if use requests in basic way. if start using stream=true need concern whether or not entire response has been read, , whether or not should closed. otherwise, should never concern of yours.


Comments

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -