summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2014-11-07 08:55:17 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2014-11-07 08:55:18 -0600
commit3155bc99362a8c6ab136b6a3bb999732617cd2e5 (patch)
tree13f79e651afc4f02e6edaac16e8c18754441d1ce
parent1c52d15d9772e459add567cbdc9d38a284a8d939 (diff)
downloadpython-requests-3155bc99362a8c6ab136b6a3bb999732617cd2e5.tar.gz
Close sessions created in the functional API
This is related to #1882 and #1685. By calling close on the session, we clear the PoolManager operated by the Session and close all sockets. Fixes #1882 Partially-fixes #1685
-rw-r--r--requests/api.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/requests/api.py b/requests/api.py
index 4eaaf9e6..1469b05c 100644
--- a/requests/api.py
+++ b/requests/api.py
@@ -46,7 +46,12 @@ def request(method, url, **kwargs):
"""
session = sessions.Session()
- return session.request(method=method, url=url, **kwargs)
+ response = session.request(method=method, url=url, **kwargs)
+ # By explicitly closing the session, we avoid leaving sockets open which
+ # can trigger a ResourceWarning in some cases, and look like a memory leak
+ # in others.
+ session.close()
+ return response
def get(url, **kwargs):