diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2016-04-25 10:31:36 -0700 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2016-04-25 10:31:36 -0700 |
commit | 48ec43b2009ca5fd8b417849fa73af20b43d1c18 (patch) | |
tree | 98bfe9efb49817d9aa8b3153b6a3db78f15b0b19 /paramiko/sftp_file.py | |
parent | dfc7b66f3ccd659fe8ffc4ba5bd108a27704182a (diff) | |
parent | 3b8ebc9292f22aaeeb3979260cd91a2969fff166 (diff) | |
download | paramiko-48ec43b2009ca5fd8b417849fa73af20b43d1c18.tar.gz |
Merge branch '1.16' into 1.17
Diffstat (limited to 'paramiko/sftp_file.py')
-rw-r--r-- | paramiko/sftp_file.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index f90fa068..fdf667cd 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -389,7 +389,7 @@ class SFTPFile (BufferedFile): """ self.pipelined = pipelined - def prefetch(self, file_size): + 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 @@ -401,8 +401,24 @@ 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. """ + 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 |