diff --git a/sshtunnel.py b/sshtunnel.py index 50d64a35..f9b3308e 100644 --- a/sshtunnel.py +++ b/sshtunnel.py @@ -46,8 +46,6 @@ TRACE_LEVEL = 1 _CONNECTION_COUNTER = 1 _LOCK = threading.Lock() -#: Timeout (seconds) for the connection to the SSH gateway, ``None`` to disable -SSH_TIMEOUT = None DEPRECATIONS = { 'ssh_address': 'ssh_address_or_host', 'ssh_host': 'ssh_address_or_host', @@ -644,6 +642,15 @@ class SSHTunnelForwarder(object): .. versionadded:: 0.0.8 + gateway_timeout (float): + Time in seconds defining the period after which, if no tunnel + has been created, the connection attempt is stopped and a + :class:`BaseSSHTunnelForwarderError` is raised. + + Default: ``None`` (disabled) + + .. versionadded:: 0.1.3 + set_keepalive (float): Interval in seconds defining the period in which, if no data was sent over the connection, a *'keepalive'* packet will be @@ -825,6 +832,7 @@ def __init__( mute_exceptions=False, remote_bind_address=None, remote_bind_addresses=None, + gateway_timeout=None, set_keepalive=0.0, threaded=True, # old version False compression=None, @@ -840,6 +848,7 @@ def __init__( self.ssh_host_key = ssh_host_key self.set_keepalive = set_keepalive + self.gateway_timeout = gateway_timeout self._server_list = [] # reset server list self.tunnel_is_up = {} # handle tunnel status self._threaded = threaded @@ -1113,7 +1122,7 @@ def _get_transport(self): else: _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if isinstance(_socket, socket.socket): - _socket.settimeout(SSH_TIMEOUT) + _socket.settimeout(self.gateway_timeout) _socket.connect((self.ssh_host, self.ssh_port)) transport = paramiko.Transport(_socket) transport.set_keepalive(self.set_keepalive)