Skip to content

Commit 8eb7756

Browse files
authored
close filesystem on delete (#319)
* close filesystem on delete * changelog
1 parent 0631416 commit 8eb7756

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
- `MemFS` now immediately releases all memory it holds when `close()` is called,
1717
rather than when it gets garbage collected. Closes [issue #308](https://github.com/PyFilesystem/pyfilesystem2/issues/308).
1818
- `FTPFS` now translates `EOFError` into `RemoteConnectionError`. Closes [#292](https://github.com/PyFilesystem/pyfilesystem2/issues/292)
19+
- Added automatic close for filesystems that go out of scope. Fixes [#298](https://github.com/PyFilesystem/pyfilesystem2/issues/298)
1920

2021
## [2.4.8] - 2019-06-12
2122

fs/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ def __init__(self):
112112
self._lock = threading.RLock()
113113
super(FS, self).__init__()
114114

115+
def __del__(self):
116+
"""Auto-close the filesystem on exit."""
117+
self.close()
118+
115119
def __enter__(self):
116120
# type: (...) -> FS
117121
"""Allow use of filesystem as a context manager.

0 commit comments

Comments
 (0)