mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-22 07:04:44 +00:00
remove expired connections
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2287 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
559c4f0432
commit
d1fd01f669
2 changed files with 22 additions and 0 deletions
|
|
@ -23,6 +23,10 @@
|
|||
Closes: SF bug #1117839
|
||||
Changed: linkcheck/checker/fileurl.py
|
||||
|
||||
* Regularly remove expired connections from the connection pool.
|
||||
Type: feature
|
||||
Changed: linkcheck/checker/pool.py
|
||||
|
||||
2.3 "Napoleon Dynamite" (released 3.2.2005)
|
||||
|
||||
* Use and require Python >= 2.4.
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class ConnectionPool (object):
|
|||
# open connections
|
||||
# {(type, host, user, pass) -> [connection, status, expiration time]}
|
||||
self.connections = {}
|
||||
self.expiration_counter = 1
|
||||
|
||||
def add_connection (self, key, conn, timeout):
|
||||
"""
|
||||
|
|
@ -54,6 +55,11 @@ class ConnectionPool (object):
|
|||
@return: Open connection object or None if no connection is available.
|
||||
@rtype None or FTPConnection or HTTP(S)Connection
|
||||
"""
|
||||
if (self.expiration_counter % 100) == 0:
|
||||
self.expiration_counter = 1
|
||||
self.expire_connections()
|
||||
else:
|
||||
self.expiration_counter += 1
|
||||
if key not in self.connections:
|
||||
# not found
|
||||
return None
|
||||
|
|
@ -84,3 +90,15 @@ class ConnectionPool (object):
|
|||
"""
|
||||
if key in self.connections:
|
||||
self.connections[key][1] = 'available'
|
||||
|
||||
def expire_connections (self):
|
||||
"""
|
||||
Remove expired connections from this pool.
|
||||
"""
|
||||
t = time.time()
|
||||
to_delete = []
|
||||
for key, conn_data in self.connections.iteritems():
|
||||
if conn_data[1] == 'available' and t > conn_data[2]:
|
||||
to_delete.append(key)
|
||||
for key in to_delete:
|
||||
del self.connections[key]
|
||||
|
|
|
|||
Loading…
Reference in a new issue