MCPcopy Create free account
hub / github.com/pytorch/pytorch / close_streams

Method close_streams

torch/utils/data/datapipes/utils/common.py:316–329  ·  view source on GitHub ↗

Traverse structure and attempts to close all found StreamWrappers on best effort basis.

(cls, v, depth=0)

Source from the content-addressed store, hash-verified

314
315 @classmethod
316 def close_streams(cls, v, depth=0):
317 """Traverse structure and attempts to close all found StreamWrappers on best effort basis."""
318 if depth > 10:
319 return
320 if isinstance(v, StreamWrapper):
321 v.close()
322 else:
323 # Traverse only simple structures
324 if isinstance(v, dict):
325 for vv in v.values():
326 cls.close_streams(vv, depth=depth + 1)
327 elif isinstance(v, (list, tuple)):
328 for vv in v:
329 cls.close_streams(vv, depth=depth + 1)
330
331 def __getattr__(self, name):
332 file_obj = self.__dict__['file_obj']

Callers 4

__iter__Method · 0.80
_cleanupMethod · 0.80
_find_nextMethod · 0.80
_cleanupMethod · 0.80

Calls 3

isinstanceFunction · 0.85
closeMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected