Skip to content

Commit

Permalink
Merge pull request #209 from pahaz/deprecate_block_on_close
Browse files Browse the repository at this point in the history
Major update
  • Loading branch information
pahaz authored Nov 15, 2020
2 parents 73d5614 + e9577af commit 9f0728e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ time.
with sshtunnel.open_tunnel(
ssh_address_or_host=('GW1_ip', 20022),
remote_bind_address=('GW2_ip', 22),
block_on_close=False
) as tunnel1:
print('Connection to tunnel1 (GW1_ip:GW1_port) OK...')
with sshtunnel.open_tunnel(
ssh_address_or_host=('localhost', tunnel1.local_bind_port),
remote_bind_address=('target_ip', 22),
ssh_username='GW2_user',
ssh_password='GW2_pwd',
block_on_close=False
) as tunnel2:
print('Connection to tunnel2 (GW2_ip:GW2_port) OK...')
with SSHClient() as ssh:
Expand Down
20 changes: 11 additions & 9 deletions sshtunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,10 @@ def stop(self, force=False):
force (bool):
Force close current connections
Default: False
.. versionadded:: 0.2.2
.. note:: This **had** to be handled with care before ``0.1.0``:
- if a port redirection is opened
Expand Down Expand Up @@ -1590,7 +1594,7 @@ def __enter__(self):
self.__exit__()

def __exit__(self, *args):
self._stop_transport()
self.stop(force=True)


def open_tunnel(*args, **kwargs):
Expand All @@ -1614,12 +1618,6 @@ def open_tunnel(*args, **kwargs):
.. versionadded:: 0.1.0
block_on_close (boolean):
Wait until all connections are done during close by changing the
value of :attr:`~SSHTunnelForwarder.block_on_close`
Default: True
.. note::
A value of ``debug_level`` set to 1 == ``TRACE`` enables tracing mode
.. note::
Expand Down Expand Up @@ -1658,15 +1656,19 @@ def do_something(port):
ssh_port = kwargs.pop('ssh_port', 22)
skip_tunnel_checkup = kwargs.pop('skip_tunnel_checkup', True)
block_on_close = kwargs.pop('block_on_close', _DAEMON)
if block_on_close:
warnings.warn("'block_on_close' is DEPRECATED. You should use either"
" .stop() or .stop(force=True), depends on what you do"
" with the active connections. This option has no"
" affect since 0.3.0",
DeprecationWarning)
if not args:
if isinstance(ssh_address_or_host, tuple):
args = (ssh_address_or_host, )
else:
args = ((ssh_address_or_host, ssh_port), )
forwarder = SSHTunnelForwarder(*args, **kwargs)
forwarder.skip_tunnel_checkup = skip_tunnel_checkup
forwarder.daemon_forward_servers = not block_on_close
forwarder.daemon_transport = not block_on_close
return forwarder


Expand Down

0 comments on commit 9f0728e

Please sign in to comment.