summaryrefslogtreecommitdiffhomepage
path: root/paramiko/sftp_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'paramiko/sftp_file.py')
-rw-r--r--paramiko/sftp_file.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py
index b3c1d648..8d147342 100644
--- a/paramiko/sftp_file.py
+++ b/paramiko/sftp_file.py
@@ -378,8 +378,8 @@ class SFTPFile (BufferedFile):
.. versionadded:: 1.5
"""
self.pipelined = pipelined
-
- def prefetch(self):
+
+ def prefetch(self, file_size=None):
"""
Pre-fetch the remaining contents of this file in anticipation of future
`.read` calls. If reading the entire file, pre-fetching can
@@ -391,14 +391,29 @@ class SFTPFile (BufferedFile):
data may be read in a random order (using `.seek`); chunks of the
buffer that haven't been read will continue to be buffered.
+ :param int file_size:
+ When this is ``None`` (the default), this method calls `stat` to
+ determine the remote file size. In some situations, doing so can
+ cause exceptions or hangs (see `#562
+ <https://github.com/paramiko/paramiko/pull/562>`_); as a
+ workaround, one may call `stat` explicitly and pass its value in
+ via this parameter.
+
.. versionadded:: 1.5.1
+ .. versionchanged:: 1.16.0
+ The ``file_size`` parameter was added (with no default value).
+ .. versionchanged:: 1.16.1
+ The ``file_size`` parameter was made optional for backwards
+ compatibility.
"""
- size = self.stat().st_size
+ if file_size is None:
+ file_size = self.stat().st_size;
+
# queue up async reads for the rest of the file
chunks = []
n = self._realpos
- while n < size:
- chunk = min(self.MAX_REQUEST_SIZE, size - n)
+ while n < file_size:
+ chunk = min(self.MAX_REQUEST_SIZE, file_size - n)
chunks.append((n, chunk))
n += chunk
if len(chunks) > 0: