tostorchconnector 1.0.3__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tostorchconnector might be problematic. Click here for more details.

Files changed (21) hide show
  1. {tostorchconnector-1.0.3/tostorchconnector.egg-info → tostorchconnector-1.0.4}/PKG-INFO +1 -1
  2. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/pyproject.toml +1 -1
  3. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_object_reader.py +15 -5
  4. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4/tostorchconnector.egg-info}/PKG-INFO +1 -1
  5. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/LICENSE +0 -0
  6. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/README.md +0 -0
  7. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/setup.cfg +0 -0
  8. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tests/test_tos_dataset.py +0 -0
  9. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tests/test_tosnativeclient.py +0 -0
  10. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/__init__.py +0 -0
  11. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_checkpoint.py +0 -0
  12. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_client.py +0 -0
  13. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_common.py +0 -0
  14. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_iterable_dataset.py +0 -0
  15. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_map_dataset.py +0 -0
  16. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_object_meta.py +0 -0
  17. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector/tos_object_writer.py +0 -0
  18. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector.egg-info/SOURCES.txt +0 -0
  19. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector.egg-info/dependency_links.txt +0 -0
  20. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector.egg-info/requires.txt +0 -0
  21. {tostorchconnector-1.0.3 → tostorchconnector-1.0.4}/tostorchconnector.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tostorchconnector
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: TOS connector integration for PyTorch
5
5
  Author-email: xiangshijian <xiangshijian@bytedance.com>
6
6
  Classifier: Development Status :: 4 - Beta
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "tostorchconnector"
8
- version = "1.0.3"
8
+ version = "1.0.4"
9
9
  description = "TOS connector integration for PyTorch"
10
10
  authors = [{ name = "xiangshijian", email = "xiangshijian@bytedance.com" }]
11
11
  requires-python = ">=3.8,<3.13"
@@ -1,5 +1,6 @@
1
1
  import io
2
2
  import logging
3
+ import threading
3
4
  from functools import cached_property
4
5
  from os import SEEK_SET, SEEK_CUR, SEEK_END
5
6
  from typing import Optional, Callable, Any
@@ -28,6 +29,8 @@ class TosObjectReader(io.BufferedIOBase):
28
29
  self._total_size: Optional[int] = None
29
30
  self._read_offset = 0
30
31
  self._buffer = io.BytesIO()
32
+ self._closed = False
33
+ self._lock = threading.Lock()
31
34
 
32
35
  @property
33
36
  def bucket(self) -> str:
@@ -47,7 +50,14 @@ class TosObjectReader(io.BufferedIOBase):
47
50
  except:
48
51
  pass
49
52
  else:
50
- if self._object_stream is not None:
53
+ self.close()
54
+
55
+ def close(self) -> None:
56
+ with self._lock:
57
+ if self._closed:
58
+ return
59
+ self._closed = True
60
+ if self._object_stream and isinstance(self._object_stream, ReadStream):
51
61
  self._object_stream.close()
52
62
 
53
63
  def read(self, size: Optional[int] = None) -> Optional[bytes]:
@@ -65,12 +75,12 @@ class TosObjectReader(io.BufferedIOBase):
65
75
  while 1:
66
76
  chunk = self._object_stream.read(self._object_stream_offset, chunk_size)
67
77
  if not chunk:
68
- self._object_stream.close()
78
+ self.close()
69
79
  break
70
80
  self._object_stream_offset += len(chunk)
71
81
  self._buffer.write(chunk)
72
82
  except:
73
- self._object_stream.close()
83
+ self.close()
74
84
  raise
75
85
 
76
86
  elif isinstance(self._object_stream, GetObjectOutput):
@@ -165,13 +175,13 @@ class TosObjectReader(io.BufferedIOBase):
165
175
  while offset > size:
166
176
  chunk = self._object_stream.read(self._object_stream_offset, chunk_size)
167
177
  if not chunk:
168
- self._object_stream.close()
178
+ self.close()
169
179
  break
170
180
  size += self._buffer.write(chunk)
171
181
  self._object_stream_offset += len(chunk)
172
182
  self._total_size = self._buffer.tell()
173
183
  except:
174
- self._object_stream.close()
184
+ self.close()
175
185
  raise
176
186
  elif isinstance(self._object_stream, GetObjectOutput):
177
187
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tostorchconnector
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: TOS connector integration for PyTorch
5
5
  Author-email: xiangshijian <xiangshijian@bytedance.com>
6
6
  Classifier: Development Status :: 4 - Beta