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
"""
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):