MCPcopy
hub / github.com/urllib3/urllib3 / _get_conn

Method _get_conn

src/urllib3/connectionpool.py:256–292  ·  view source on GitHub ↗

Get a connection. Will return a pooled connection if one is available. If no connections are available and :prop:`.block` is ``False``, then a fresh connection is returned. :param timeout: Seconds to wait before giving up and raising :class:

(self, timeout: float | None = None)

Source from the content-addressed store, hash-verified

254 return conn
255
256 def _get_conn(self, timeout: float | None = None) -> BaseHTTPConnection:
257 """
258 Get a connection. Will return a pooled connection if one is available.
259
260 If no connections are available and :prop:`.block` is ``False``, then a
261 fresh connection is returned.
262
263 :param timeout:
264 Seconds to wait before giving up and raising
265 :class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and
266 :prop:`.block` is ``True``.
267 """
268 conn = None
269
270 if self.pool is None:
271 raise ClosedPoolError(self, "Pool is closed.")
272
273 try:
274 conn = self.pool.get(block=self.block, timeout=timeout)
275
276 except AttributeError: # self.pool is None
277 raise ClosedPoolError(self, "Pool is closed.") from None # Defensive:
278
279 except queue.Empty:
280 if self.block:
281 raise EmptyPoolError(
282 self,
283 "Pool is empty and a new connection can't be opened due to blocking mode.",
284 ) from None
285 pass # Oh well, we'll create a new connection then
286
287 # If this is a persistent connection, check if it got disconnected
288 if conn and is_connection_dropped(conn):
289 log.debug("Resetting dropped connection: %s", self.host)
290 conn.close()
291
292 return conn or self._new_conn()
293
294 def _put_conn(self, conn: BaseHTTPConnection | None) -> None:
295 """

Calls 6

_new_connMethod · 0.95
ClosedPoolErrorClass · 0.85
EmptyPoolErrorClass · 0.85
is_connection_droppedFunction · 0.85
getMethod · 0.80
closeMethod · 0.45