@@ -238,31 +238,31 @@ def _assign_requests_to_connections(self) -> List[AsyncConnectionInterface]:
238
238
those connections to be handled seperately.
239
239
"""
240
240
closing_connections = []
241
- idling_count = sum ( 1 for c in self . _connections if c . is_idle ())
241
+ idling_count = 0
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_count -= int (connection .is_idle ())
250
249
elif connection .has_expired ():
251
250
# log: "closing expired connection"
252
251
self ._connections .remove (connection )
253
252
closing_connections .append (connection )
254
- idling_count -= int ( connection .is_idle ())
255
- elif (
256
- connection . is_idle () and idling_count > self . _max_keepalive_connections
257
- ):
253
+ elif connection .is_idle ():
254
+ if idling_count < self . _max_keepalive_connections :
255
+ idling_count += 1
256
+ continue
258
257
# log: "closing idle connection"
259
258
self ._connections .remove (connection )
260
259
closing_connections .append (connection )
261
- idling_count -= 1
262
260
263
261
# Assign queued requests to connections.
264
- queued_requests = [request for request in self ._requests if request .is_queued ()]
265
- for pool_request in queued_requests :
262
+ for pool_request in list (self ._requests ):
263
+ if not pool_request .is_queued ():
264
+ continue
265
+
266
266
origin = pool_request .request .url .origin
267
267
available_connections = [
268
268
connection
0 commit comments