diff options
author | Robey Pointer <robey@ralph.lag.net> | 2005-12-02 20:32:06 -0800 |
---|---|---|
committer | Robey Pointer <robey@ralph.lag.net> | 2005-12-02 20:32:06 -0800 |
commit | a8778ffe6f81eeace5e4531e02a0818f3a98422b (patch) | |
tree | 8f610b9b7218c83e28207d93943c4506be3b23c9 | |
parent | 62a83e7d03b2ddf528fc3a8fe6b87f2cdfa68807 (diff) |
[project @ robey@ralph.lag.net-20051203043206-1a5ab28112642246]
when closing an sftp file because of __del__, don't wait for a response, just shoot off a request and leave (on linux, the GC is run from a devoted thread)
-rw-r--r-- | paramiko/sftp_file.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index e8f42dcd..f224f025 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -46,9 +46,9 @@ class SFTPFile (BufferedFile): self._saved_exception = None def __del__(self): - self.close() + self.close(_async=True) - def close(self): + def close(self, _async=False): # 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 @@ -62,7 +62,11 @@ class SFTPFile (BufferedFile): self.sftp._finish_responses(self) BufferedFile.close(self) try: - self.sftp._request(CMD_CLOSE, self.handle) + if _async: + # GC'd file handle could be called from an arbitrary thread -- don't wait for a response + self.sftp._async_request(type(None), CMD_CLOSE, self.handle) + else: + self.sftp._request(CMD_CLOSE, self.handle) except EOFError: # may have outlived the Transport connection pass @@ -71,6 +75,7 @@ class SFTPFile (BufferedFile): pass def _read_prefetch(self, size): + # while not closed, and haven't fetched past the current position, and haven't reached EOF... while (self._prefetch_so_far <= self._realpos) and \ (self._prefetch_so_far < self._prefetch_size) and not self._closed: self.sftp._read_response() |