Closing requests for python request
1 answer
Yes, there is a call session.close
behind the code get
. If you're using a suitable IDE like PyCharm you can follow the code get
to see what's going on. Inside get
there is a request for a request:
return request('get', url, params=params, **kwargs)
The request
call is made in the definition of this method session.close
.
By following the link here for the repo request a call is made to control the session:
# By using the 'with' statement we are sure the session is closed, thus we
# avoid leaving sockets open which can trigger a ResourceWarning in some
# cases, and look like a memory leak in others.
with sessions.Session() as session:
return session.request(method=method, url=url, **kwargs)
+5
source to share