@@ -238,28 +238,27 @@ def _assign_requests_to_connections(self) -> List[AsyncConnectionInterface]:
238
238
those connections to be handled seperately.
239
239
"""
240
240
closing_connections = []
241
- idling_connections = { c for c in self ._connections if c .is_idle ()}
241
+ idling_count = sum ( 1 for c in self ._connections if c .is_idle ())
242
242
243
243
# First we handle cleaning up any connections that are closed,
244
244
# have expired their keep-alive, or surplus idle connections.
245
245
for connection in list (self ._connections ):
246
246
if connection .is_closed ():
247
247
# log: "removing closed connection"
248
248
self ._connections .remove (connection )
249
- idling_connections . discard (connection )
249
+ idling_count -= int (connection . is_idle () )
250
250
elif connection .has_expired ():
251
251
# log: "closing expired connection"
252
252
self ._connections .remove (connection )
253
- idling_connections .discard (connection )
254
253
closing_connections .append (connection )
254
+ idling_count -= int (connection .is_idle ())
255
255
elif (
256
- connection .is_idle ()
257
- and len (idling_connections ) > self ._max_keepalive_connections
256
+ connection .is_idle () and idling_count > self ._max_keepalive_connections
258
257
):
259
258
# log: "closing idle connection"
260
259
self ._connections .remove (connection )
261
- idling_connections .discard (connection )
262
260
closing_connections .append (connection )
261
+ idling_count -= 1
263
262
264
263
# Assign queued requests to connections.
265
264
queued_requests = [request for request in self ._requests if request .is_queued ()]
0 commit comments