Skip to content
Myr

Assure session is closed on exception.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Artur Siekielski · committed by Artur Siekielski · parent f7e0494 · Browse files · 1 file+5 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−7 removed

  • other:+5 added−7 removed

1 file+5 added−7 removed

modified:requests/api.py+5 added-7 removed
44 unmodified lines
45 >>> req = requests.request('GET', 'http://httpbin.org/get')46 <Response [200]>47 """4849 session = sessions.Session()50 response = session.request(method=method, url=url, **kwargs)51 # By explicitly closing the session, we avoid leaving sockets open which52 # can trigger a ResourceWarning in some cases, and look like a memory leak53 # in others.54 session.close()55 return response49 # By using the 'with' statement we are sure the session is closed, thus we50 # avoid leaving sockets open which can trigger a ResourceWarning in some51 # cases, and look like a memory leak in others.52 with sessions.Session() as session:53 return session.request(method=method, url=url, **kwargs)545556def get(url, params=None, **kwargs):57 """Sends a GET request.
88 unmodified lines