diff options
Diffstat (limited to 'paramiko/transport.py')
-rw-r--r-- | paramiko/transport.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/paramiko/transport.py b/paramiko/transport.py index 000a98f3..9fcaa9fb 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -58,7 +58,7 @@ from paramiko.kex_gss import KexGSSGex, KexGSSGroup1, KexGSSGroup14, NullHostKey from paramiko.message import Message from paramiko.packet import Packetizer, NeedRekeyException from paramiko.primes import ModulusPack -from paramiko.py3compat import string_types, long, byte_ord, b, input +from paramiko.py3compat import string_types, long, byte_ord, b, input, PY2 from paramiko.rsakey import RSAKey from paramiko.ecdsakey import ECDSAKey from paramiko.server import ServerInterface @@ -1533,17 +1533,23 @@ class Transport (threading.Thread, ClosingContextManager): def stop_thread(self): self.active = False self.packetizer.close() - # Keep trying to join() our main thread, quickly, until: - # * We join()ed successfully (self.is_alive() == False) - # * Or it looks like we've hit issue #520 (socket.recv hitting some - # race condition preventing it from timing out correctly), wherein our - # socket and packetizer are both closed (but where we'd otherwise be - # sitting forever on that recv()). - while ( - self.is_alive() and self is not threading.current_thread() - and not self.sock._closed and not self.packetizer.closed - ): - self.join(0.1) + if PY2: + # Original join logic; #520 doesn't appear commonly present under + # Python 2. + while self.is_alive() and self is not threading.current_thread(): + self.join(10) + else: + # Keep trying to join() our main thread, quickly, until: + # * We join()ed successfully (self.is_alive() == False) + # * Or it looks like we've hit issue #520 (socket.recv hitting some + # race condition preventing it from timing out correctly), wherein + # our socket and packetizer are both closed (but where we'd + # otherwise be sitting forever on that recv()). + while ( + self.is_alive() and self is not threading.current_thread() + and not self.sock._closed and not self.packetizer.closed + ): + self.join(0.1) ### internals... |