MCPcopy
hub / github.com/aio-libs/aiohttp / _cleanup

Method _cleanup

aiohttp/connector.py:181–215  ·  view source on GitHub ↗

Cleanup unused transports.

(self)

Source from the content-addressed store, hash-verified

179 return self._limit
180
181 def _cleanup(self):
182 """Cleanup unused transports."""
183 if self._cleanup_handle:
184 self._cleanup_handle.cancel()
185 self._cleanup_handle = None
186
187 now = self._loop.time()
188
189 connections = {}
190 timeout = self._keepalive_timeout
191
192 for key, conns in self._conns.items():
193 alive = []
194 for transport, proto, t0 in conns:
195 if transport is not None:
196 if proto and not proto.is_connected():
197 transport = None
198 else:
199 delta = t0 + self._keepalive_timeout - now
200 if delta < 0:
201 transport.close()
202 transport = None
203 elif delta < timeout:
204 timeout = delta
205
206 if transport is not None:
207 alive.append((transport, proto, t0))
208 if alive:
209 connections[key] = alive
210
211 if connections:
212 self._cleanup_handle = self._loop.call_at(
213 ceil(now + timeout), self._cleanup)
214
215 self._conns = connections
216
217 def _start_cleanup_task(self):
218 if self._cleanup_handle is None:

Callers 3

test_cleanupMethod · 0.95
test_cleanup2Method · 0.95
test_cleanup3Method · 0.95

Calls 3

is_connectedMethod · 0.80
appendMethod · 0.80
closeMethod · 0.45

Tested by 3

test_cleanupMethod · 0.76
test_cleanup2Method · 0.76
test_cleanup3Method · 0.76