Skip to content

Commit cb36bec

Browse files
authored
Fix closing contexts of tar and zip files and add test 3.14t in CI (#2012)
1 parent 0bb819c commit cb36bec

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

.github/workflows/main.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
linux:
11-
name: ${{ matrix.PY }}-pytest
11+
name: ${{ matrix.PY }}${{ matrix.FREETHREADING && 't' || '' }}-pytest
1212
runs-on: ubuntu-24.04
1313
strategy:
1414
fail-fast: false
@@ -19,6 +19,11 @@ jobs:
1919
- "3.12"
2020
- "3.13"
2121
- "3.14"
22+
FREETHREADING:
23+
- false
24+
include:
25+
- PY: "3.14"
26+
FREETHREADING: true
2227

2328
env:
2429
CIRUN: true
@@ -29,6 +34,10 @@ jobs:
2934
with:
3035
fetch-depth: 0
3136

37+
- name: Patch env file to use freethreaded Python
38+
if: fromJSON(matrix.FREETHREADING)
39+
run: echo " - python-freethreading" >> ci/environment-linux.yml
40+
3241
- name: Setup conda
3342
uses: conda-incubator/setup-miniconda@v3
3443
with:

fsspec/implementations/tar.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,14 @@ def _open(self, path, mode="rb", **kwargs):
122122
if details["type"] != "file":
123123
raise ValueError("Can only handle regular files")
124124
return self.tar.extractfile(path)
125+
126+
def close(self):
127+
"""Commits any write changes to the file. Done on ``del`` too."""
128+
self.tar.close()
129+
130+
def __del__(self):
131+
if hasattr(self, "tar"):
132+
self.close()
133+
del self.tar
134+
if hasattr(self, "of") and hasattr(self.of, "__exit__"):
135+
self.of.__exit__(None, None, None)

fsspec/implementations/zip.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __del__(self):
7878
if hasattr(self, "zip"):
7979
self.close()
8080
del self.zip
81+
if hasattr(self, "of") and hasattr(self.of, "__exit__"):
82+
self.of.__exit__(None, None, None)
8183

8284
def close(self):
8385
"""Commits any write changes to the file. Done on ``del`` too."""

0 commit comments

Comments
 (0)