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.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py
index 6b8e9350..854ccf4a 100644
--- a/paramiko/sftp_file.py
+++ b/paramiko/sftp_file.py
@@ -45,6 +45,15 @@ class SFTPFile (BufferedFile):
self.close()
def close(self):
+ # We allow double-close without signaling an error, because real
+ # Python file objects do. However, we must protect against actually
+ # sending multiple CMD_CLOSE packets, because after we close our
+ # handle, the same handle may be re-allocated by the server, and we
+ # may end up mysteriously closing some random other file. (This is
+ # especially important because we unconditionally call close() from
+ # __del__.)
+ if self._closed:
+ return
BufferedFile.close(self)
try:
self.sftp._request(CMD_CLOSE, self.handle)