-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix connection timeouts in pool #27
Conversation
@@ -125,6 +125,10 @@ def acquire(self): | |||
conn = self._free.popleft() | |||
assert not conn.closed, conn | |||
assert conn not in self._used, (conn, self._used) | |||
# drop if connection timedout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you move the patch into _fill_free_pool()
method?
It makes code more clear from my perspective.
Just iterate over _free
list and drop all timed-out connections.
Done. |
# iterate over free connections and remove timeouted ones | ||
free_size = len(self._free) | ||
n = 0 | ||
while n < free_size: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Still not perfect: you are removing connection from deque and pushing it back if it is not closed (which is most likely happens).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about instead pop/appendleft
use rotate
? This method does not perform unnecessary removals and just relink underlying linked list:
while n < free_size:
conn = self._free[-1]
if conn._reader.at_eof():
self._free.pop()
conn.close()
else:
self._free.rotate()
n += 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
fix connection timeouts in pool
Should fix #25 and #16
@asvetlov please review.