Skip to content

Commit

Permalink
Merge branch '1.13' into 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Dec 18, 2014
2 parents cca8c51 + 741b4fb commit e088252
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 12 additions & 7 deletions paramiko/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from subprocess import Popen, PIPE
from select import select
import socket
import time

from paramiko.ssh_exception import ProxyCommandFailure

Expand Down Expand Up @@ -76,20 +77,24 @@ def recv(self, size):
:return: the length of the read content, as an `int`
"""
try:
start = datetime.now()
start = time.time()
while len(self.buffer) < size:
select_timeout = None
if self.timeout is not None:
elapsed = (datetime.now() - start).microseconds
timeout = self.timeout * 1000 * 1000 # to microseconds
if elapsed >= timeout:
elapsed = (time.time() - start)
if elapsed >= self.timeout:
raise socket.timeout()
r, w, x = select([self.process.stdout], [], [], 0.0)
select_timeout = self.timeout - elapsed

r, w, x = select(
[self.process.stdout], [], [], select_timeout)
if r and r[0] == self.process.stdout:
b = os.read(self.process.stdout.fileno(), 1)
b = os.read(
self.process.stdout.fileno(), size - len(self.buffer))
# Store in class-level buffer for persistence across
# timeouts; this makes us act more like a real socket
# (where timeouts don't actually drop data.)
self.buffer.append(b)
self.buffer.extend(b)
result = ''.join(self.buffer)
self.buffer = []
return result
Expand Down
5 changes: 5 additions & 0 deletions sites/www/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

* :bug:`413` (also :issue:`414`, :issue:`420`, :issue:`454`) Be significantly
smarter about polling & timing behavior when running proxy commands, to avoid
unnecessary (often 100%!) CPU usage. Major thanks to Jason Dunsmore for
report & initial patchset and to Chris Adams & John Morrissey for followup
improvements.
* :bug:`428` Fix an issue in `~paramiko.file.BufferedFile` (primarily used in
the SFTP modules) concerning incorrect behavior by
`~paramiko.file.BufferedFile.readlines` on files whose size exceeds the
Expand Down

0 comments on commit e088252

Please sign in to comment.