From: Ian Cordasco Date: Fri, 7 Nov 2014 14:55:17 +0000 (-0600) Subject: Close sessions created in the functional API X-Git-Tag: v2.5.0~9^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3155bc99362a8c6ab136b6a3bb999732617cd2e5;p=services%2Fpython-requests.git 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 --- diff --git a/requests/api.py b/requests/api.py index 4eaaf9e..1469b05 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):