Found while I was writing tests for PR #1207 that this code in each iteration requests for the original number of sessions in every loop iteration
|
while not self._sessions.full(): |
|
resp = api.batch_create_sessions( |
|
request=request, |
|
metadata=metadata, |
|
) |
|
for session_pb in resp.session: |
|
session = self._new_session() |
|
session._session_id = session_pb.name.split("/")[-1] |
|
self._sessions.put(session) |
and the basic tests inside tests/unit/test_pool.py when ran, the loop runs twice but each time the count is kept the exact same per
|
resp = api.batch_create_sessions( |
|
request=request, |
|
metadata=metadata, |
|
) |
You can add prints and you'll see that the loop runs twice but each time 2 sessions are returned but yet 4 sessions were requested
Suggestion
The correct remedy for this is that per iteration, the current size of the filled in queue must be considered in relation to filling it up request.session_count = requested_session_count - self._sessions.qsize()