MCPcopy
hub / github.com/urllib3/urllib3 / _put_conn

Method _put_conn

src/urllib3/connectionpool.py:294–335  ·  view source on GitHub ↗

Put a connection back into the pool. :param conn: Connection object for the current host and port as returned by :meth:`._new_conn` or :meth:`._get_conn`. If the pool is already full, the connection is closed and discarded because we exceede

(self, conn: BaseHTTPConnection | None)

Source from the content-addressed store, hash-verified

292 return conn or self._new_conn()
293
294 def _put_conn(self, conn: BaseHTTPConnection | None) -> None:
295 """
296 Put a connection back into the pool.
297
298 :param conn:
299 Connection object for the current host and port as returned by
300 :meth:`._new_conn` or :meth:`._get_conn`.
301
302 If the pool is already full, the connection is closed and discarded
303 because we exceeded maxsize. If connections are discarded frequently,
304 then maxsize should be increased.
305
306 If the pool is closed, then the connection will be closed and discarded.
307 """
308 if self.pool is not None:
309 try:
310 self.pool.put(conn, block=False)
311 return # Everything is dandy, done.
312 except AttributeError:
313 # self.pool is None.
314 pass
315 except queue.Full:
316 # Connection never got put back into the pool, close it.
317 if conn:
318 conn.close()
319
320 if self.block:
321 # This should never happen if you got the conn from self._get_conn
322 raise FullPoolError(
323 self,
324 "Pool reached maximum size and no more connections are allowed.",
325 ) from None
326
327 log.warning(
328 "Connection pool is full, discarding connection: %s. Connection pool size: %s",
329 self.host,
330 self.pool.qsize(),
331 )
332
333 # Connection never got put back into the pool, close it.
334 if conn:
335 conn.close()
336
337 def _validate_conn(self, conn: BaseHTTPConnection) -> None:
338 """

Calls 3

FullPoolErrorClass · 0.85
putMethod · 0.80
closeMethod · 0.45