Skip to content

Commit

Permalink
Revert Python 2 to original join logic re paramiko#520
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Jun 12, 2016
1 parent f336a34 commit 0ebd247
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions paramiko/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
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
Expand Down Expand Up @@ -1532,17 +1532,23 @@ def getpeername(self):
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...

Expand Down

0 comments on commit 0ebd247

Please sign in to comment.