I'm using python requests library with sessions:
def _get_session(self):
if not self.session:
self.session = requests.Session()
return self.session
And sometimes I'm getting this warning in my logs:
[2014/May/12 14:40:04 WARNING ] HttpConnectionPool is full, discarding connection: www.ebi.ac.uk
My question is: why this is warning and not an exception?
This is the code responsible for this (from http://pydoc.net/Python/requests/0.8.5/requests.packages.urllib3.connectionpool/):
def _put_conn(self, conn):
try:
self.pool.put(conn, block=False)
except Full:
# This should never happen if self.block == True
log.warning("HttpConnectionPool is full, discarding connection: %s"
% self.host)
Why this exception is catched here? If it was reraised, I could handle this exception in my code, by creating new session and deleting the old one.
If it's only a warning, does it mean it doesn't affect my results in any way? Can I ignore it? If not, how can I handle this situation?
self.block
toTrue
? – Glendon:param block: If set to True, no more than **maxsize** connections will be used at a time. When no free connections are available, the call will block until a connection has been released.
– Glendonblock==False
, any attempted connections past maxsize will be normally performed. The only difference is that those extra connections will not be kept in the pool afterwards, hence "discarded". That's why this is just a warning, not an exception. All connections are made. – Senna