mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-10 15:44:45 +00:00
FTP connection timeout
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2229 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
b2f158220f
commit
2c40c0be3c
2 changed files with 14 additions and 6 deletions
2
TODO
2
TODO
|
|
@ -5,7 +5,7 @@ Possible improvements people could work on:
|
|||
Must be thread-safe, must handle timeouts and connection expiration
|
||||
(HTTP: only pool persistent (ie. HTTP/1.1) connections; Keepalive
|
||||
header parsing).
|
||||
Note: FTP connection pooling is already there, but without timeouts.
|
||||
Note: FTP connection pooling is already there.
|
||||
|
||||
- [USAGE] rethink intern/extern stuff
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import linkcheck.containers
|
|||
import linkcheck.configuration
|
||||
import linkcheck.threader
|
||||
|
||||
FTP_CONNECTION_TIMEOUT = 300
|
||||
|
||||
|
||||
def _check_morsel (m, host, path):
|
||||
"""
|
||||
|
|
@ -224,12 +226,18 @@ class Cache (object):
|
|||
try:
|
||||
key = (host, username, password)
|
||||
if key in self.ftp_connections:
|
||||
conn_and_status = self.ftp_connections[key]
|
||||
if conn_and_status[1] == 'busy':
|
||||
conn_data = self.ftp_connections[key]
|
||||
t = time.time()
|
||||
if conn_data[2] - t > FTP_CONNECTION_TIMEOUT:
|
||||
# timed out
|
||||
del self.ftp_connections[key]
|
||||
return None
|
||||
if conn_data[1] == 'busy':
|
||||
# connection is in use
|
||||
return "busy"
|
||||
conn_and_status[1] = 'busy'
|
||||
return conn_and_status[0]
|
||||
conn_data[1] = 'busy'
|
||||
conn_data[2] = t
|
||||
return conn_data[0]
|
||||
return None
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
|
@ -243,7 +251,7 @@ class Cache (object):
|
|||
key = (host, username, password)
|
||||
cached = key in self.ftp_connections
|
||||
if not cached:
|
||||
self.ftp_connections[key] = [conn, 'busy']
|
||||
self.ftp_connections[key] = [conn, 'busy', time.time()]
|
||||
return cached
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
|
|
|||
Loading…
Reference in a new issue