I\'m working on a python script to query a few remote databases over an established ssh tunnel every so often. I\'m fairly familiar with the paramiko library, so that was my cho
You can also try sshtunnel it has two cases to close tunnel .stop()
if you want to wait until the end of all active connections or .stop(force=True)
to close all active connections.
If you don't want to use it you can check the source code for this logic here: https://github.com/pahaz/sshtunnel/blob/090a1c1/sshtunnel.py#L1423-L1456