8000 [DataPipe] adding a finally statement to ensure hook is reset (#70214) · pytorch/pytorch@74c834e · GitHub
[go: up one dir, main page]

Skip to content

Commit 74c834e

Browse files
NivekTfacebook-github-bot
authored andcommitted
[DataPipe] adding a finally statement to ensure hook is reset (#70214)
Summary: Pull Request resolved: #70214 cc VitalyFedyunin ejguan NivekT Test Plan: Imported from OSS Reviewed By: ejguan Differential Revision: D33255306 Pulled By: NivekT fbshipit-source-id: de2fe6bf08328e481c714aaad390db771073469e
1 parent 23902fb commit 74c834e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

torch/utils/data/graph.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def reduce_hook(obj):
4040
captured_connections.append(obj)
4141
return stub_unpickler, ()
4242

43-
# TODO(VitalyFedyunin): Better do it as `with` context for safety
44-
IterDataPipe.set_reduce_ex_hook(reduce_hook)
45-
if exclude_primitive:
46-
IterDataPipe.set_getstate_hook(getstate_hook)
4743
try:
44+
IterDataPipe.set_reduce_ex_hook(reduce_hook)
45+
if exclude_primitive:
46+
IterDataPipe.set_getstate_hook(getstate_hook)
4847
p.dump(scan_obj)
4948
except AttributeError: # unpickable DataPipesGraph
5049
pass # TODO(VitalyFedyunin): We need to tight this requirement after migrating from old DataLoader
51-
IterDataPipe.set_reduce_ex_hook(None)
52-
if exclude_primitive:
53-
IterDataPipe.set_getstate_hook(None)
50+
finally:
51+
IterDataPipe.set_reduce_ex_hook(None)
52+
if exclude_primitive:
53+
IterDataPipe.set_getstate_hook(None)
5454
return captured_connections
5555

5656

0 commit comments

Comments
 (0)
0